以下用于调整选择列表大小的JavaScript会在Google Chrome中中断.它在Tabed into the field时有效,但点击它会产生"Aw,Snap!" 错误页面.
<select onfocus="this.setAttribute('size', 3);">
<option>selectList with onfocus</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在FF和IE中工作正常.这是onfocus之间的某种冲突(如果我在onClick上实现它没有问题)和设置size属性.我被告知它也在Safari中断了.
非常感谢任何帮助,想法或解决方法.
(PS Yeh我知道调整选择列表的形式不是很好,但这是老板/客户想要的)
我正在尝试使用dom在页面<base>的开始<head>标记之后立即插入HTML 标记.我尝试过使用appendChild哪个只是在它之前插入它</head>是不好的.
代码即时使用:
$head = $dom->getElementsByTagName('head')->item(0);
$base = $dom->createElement('base');
$base->setAttribute('href', $url);
$head->parentNode->insertBefore($base, $head);
Run Code Online (Sandbox Code Playgroud)
这会在<base>之前插入标签<head>,这仍然不好!
有任何想法吗?啤酒的正确答案!
我试图在python中编写一个简单的对象,它将使用加载设置ConfigParser,将所有项目作为字典,然后将它们设置为对象的属性.
如果我不包含__setattr__方法,这似乎有效.我可以调用"settings.top_travel"并获得答案.但是,一旦我尝试放一个__setattr__,我似乎得到一个错误.
它看起来相当递归,所以我假设Get是在调用Set等.在set属性部分,我希望让它写回配置文件.因此,只要其中一个设置属性发生更改,它就会存储回文件所在的文件中.
您将在下面找到代码和错误.
import ConfigParser
class settingsFile(object):
def __init__(self):
"""
Reloads the configuration file and returns a dictionary with the
settings :
[config]
top_travel = 250
"""
# Create a configuration object and read in the file
configuration = ConfigParser.ConfigParser()
configuration.read('config/config.cfg')
# Return all the "config" section as a list and convert to a dictionary
self.configuration = dict(configuration.items("config"))
def refresh(self):
self.__init__()
def __getattr__(self, attr):
return self.configuration[attr]
def …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个弹出消息,禁用屏幕的其余部分,直到您确认它,只使用CSS和JavaScript(并且没有该alert功能).
尽管http://msdn.microsoft.com/en-us/library/ie/ms536739%28v=vs.85%29.aspx声明setAttributeIE8及更高版本支持它,但它似乎无法正常工作 - 实际上,实际上它似乎根本不起作用.
这是我的代码:
<html>
<style type="text/css">
.overlay
{
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.2);
}
.overlaytext
{
position: absolute;
left: 50%;
margin-left: -150px;
top: 50%;
margin-top: -50px;
width: 300px;
height: 100px;
padding-top: 5px;
background-color: #777777;
color: #000000;
font-size: 20px;
text-align: center;
}
.overlaybutton
{
position: absolute;
left: 50%;
margin-left: -30px;
top: 50%;
margin-top: 20px;
width: 60px;
height: 25px;
border: solid;
border-color: #000000;
border-width: 1px; …Run Code Online (Sandbox Code Playgroud) 我正在制作一个用于表单验证的插件作为实践,但是由于某种原因,在我创建了一个 h2 元素并尝试设置它的属性后,它不起作用。这是代码
var testing = function(regex, value, error_msg, error_msg_field_id){
var pattern = new RegExp(regex);
if (!pattern.test(value)){
var ele = document.createElement("H2");
var node = document.createTextNode(error_msg);
ele.setAttribute('style', 'color:white');
alert("hi");
jQuery(error_msg_field_id).append(node);
}
}
Run Code Online (Sandbox Code Playgroud)
文本显示没有问题,但不是白色的。这对我来说毫无意义
嘿,我只是意识到在ADMIN中向表单产品添加属性是多么容易,而且它的工作非常好.因此,与设置常规,价格,元信息,图像,重复配置文件,设计和更多信息的属性类似,如何向库存表单添加属性?
在此先感谢您的帮助.
我有一个非常有趣的问题.我正在写一个允许你放大/缩小图像的插件.我有3个按钮:关闭(关闭'窗口'),放大,缩小.放大/缩小按钮也有禁用版本.当您达到最小/最大变焦量时,它会被激活.
如果打开要缩放的图片,则可以看到活动的缩小按钮和禁用的放大按钮(因为我在打开时设置了最大值).当您第一次单击缩小按钮时,放大按钮应该摆脱禁用的类.它适用于Safara,Chrome,Firefox 3.6/4/5,IE8,但不适用于IE7.
放大按钮有一个ID和类,我想强制IE7从元素中删除特定的类.首先,我使用了removeClass(),但它没有用.然后我使用setAttribute(),它适用于IE7的每个浏览器.
这是一个例子.因此,当您打开要缩放的图像时,缩小按钮具有ID ="缩放按钮"和5个类:缩放图标,缩放图标小,缩放按钮,缩放按钮禁用,变焦按钮禁用项.我想删除2个'禁用'类.所以我用这个:
var elementZoomButtonIn = document.getElementById("zoom-button-in");
elementZoomButtonIn.setAttribute("class", "zoom-icon zoom-icon-small zoom-button-in");
Run Code Online (Sandbox Code Playgroud)
我已经尝试在插入非禁用类之前将类设置为空,但是没有用.
这种方法在IE7中运行吗?( - :
感谢你们!
我想将span节点的visited属性设置为true或false基于它是否已被访问。
test();
function test () {
var el = document.createElement("span");
el.setAttribute("visited", false);
el.setAttribute("visited", true);
alert(el.getAttribute("visited") === true); //False
alert(el.getAttribute("visited") === "true"); //True
}
Run Code Online (Sandbox Code Playgroud)
我最初将属性“visited”设置为 boolean false,然后将 boolean 设置为true。我注意到当我检查属性是否为 时true,它返回 false,但如果我检查字符串true,它返回 true。
在MSN文件只谈与attributeName为需要的字符串,而不是价值。那么为什么不与 bool 进行比较呢?
我是JavaScript的初学者,我无法理解为什么在这个简单的代码中,出现在控制台color.setAttribute不是一个函数
<style>
.red {color:red;}
.blue { color: blue;}
</style>
</head>
<body>
<p class="red">Hello World</p>
<script>
var color = document.getElementsByClassName("red");
color.setAttribute("class","blue");
</script>Run Code Online (Sandbox Code Playgroud)
在此先感谢,如果我的问题很愚蠢,那就很抱歉.
我必须验证iframe中没有名称/ ID的文本/消息.在探索之后,我发现了添加id/name并使用switchToIFrame(id/name)的解决方案.如何在貂皮中为节点元素设置id/name?SetAttribute()不是nodelement中支持的方法,并且帧不支持setValue().
<html>
<body>
<div class="div1">
<iframe class="xyz">
<!DOCTYPE html>
<html>
<body>
<div class="frame"></div>
<p>The paragraph1</p>
</body>
</html>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的上下文文件是
public function iShouldSeeDescription($arg1)
{
$expected = "The paragraph1";
$iframe=$this->getSession ()->getPage ()->find ( 'xpath', '//div[contains(@class,"div1")]/iframe[contains(@class,"xyz")]');
$iframe->setAttribute('id', 'iframe_id');
$iframeId = $iframe->getAttribute('id');
$this->getSession()->switchToIframe("$iframeId");
$actual = $this->getSession()->getPage()->find('xpath', '//div[@class="frame"]/p[1]');
if ($actual === null) {
throw new \InvalidArgumentException ( sprintf ( 'null:%s', $arg1 ) );
}
if (!($actual === $expected)) {
throw new \InvalidArgumentException ( sprintf ( 'The Acutal description:%s and expected description:%s did not …Run Code Online (Sandbox Code Playgroud) setattribute ×10
javascript ×6
html ×2
appendchild ×1
behat ×1
boolean ×1
dom ×1
element ×1
focus ×1
getattribute ×1
iframe ×1
inventory ×1
jquery ×1
magento ×1
mink ×1
object ×1
php ×1
product ×1
python ×1
removeclass ×1
select ×1