简体   繁体   English

JScript 按钮在 chrome 中工作但在 Firefox 中不工作

[英]JScript Button working in chrome but not in Firefox

I have a script which basically appends attributes when a button is clicked.我有一个脚本,它基本上在单击按钮时附加属性。 Script is as follows;脚本如下;

<script type="text/javascript">
window.generateRow = function() {
    var d = document.getElementById("add");
    var p = document.createElement("p");
    var input = document.createElement("input");
    input.setAttribute('type', 'text');
    input.setAttribute('pattern', '^[a-zA-Z ]+$');
    input.setAttribute('name', 'items[]');
    input.setAttribute('required');
    p.appendChild(input);
    d.appendChild(p);
}
</script>

And in my HTML I use a normal onClick function to call back the function在我的 HTML 中,我使用一个普通的 onClick 函数来回调函数

<div id="add"></div>
<p><input type="button" value="Add" name="" onclick="generateRow()"/></p>

The problem I am having is in my version of Chrome I am able to add a field each time the button is clicked, but in Firefox and a updated version of Chrome the button does not respond to anything.我遇到的问题是在我的 Chrome 版本中,每次单击按钮时我都可以添加一个字段,但是在 Firefox 和 Chrome 的更新版本中,该按钮没有任何响应。

I am using Firefox version 31.0 and i am using Chrome version 32.0我使用的是 Firefox 31.0 版,我使用的是 Chrome 32.0 版

NodeElement method setAttribute requires two arguments, but line input.setAttribute('required') has only one. NodeElement方法setAttribute需要两个参数,但行input.setAttribute('required')只有一个。 You have to use input.setAttribute('required', true);你必须使用input.setAttribute('required', true); instead.反而。

Your whole code after update:更新后的整个代码:

generateRow = function() {
    alert('m');
    var d = document.getElementById("add");
    var p = document.createElement("p");
    var input = document.createElement("input");
    input.setAttribute('type', 'text');
    input.setAttribute('pattern', '^[a-zA-Z ]+$');
    input.setAttribute('name', 'items[]');
    input.setAttribute('required', true);
    p.appendChild(input);
    d.appendChild(p);
}

DEMO演示

http://jsfiddle.net/ZZ7T5/2/ its link to fiddle problem is in setAttribute("required"). http://jsfiddle.net/ZZ7T5/2/其小提琴问题的链接在 setAttribute("required") 中。 Its asking for two params while you are only passing one它要求两个参数,而您只传递一个参数

window.generateRow = function() {
    var d = document.getElementById("add");
    var p = document.createElement("p");
    var input = document.createElement("input");
    input.setAttribute('type', 'text');
    input.setAttribute('pattern', '^[a-zA-Z ]+$');
    input.setAttribute('name', 'items[]');
    input.setAttribute('required', true); // THIS IS ERR
    p.appendChild(input);
    d.appendChild(p);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 按钮适用于Chrome,但不适用于Firefox - Button working on chrome but not on firefox 按钮可以在Chrome中使用,但不能在Firefox或IE中使用? - Button working in chrome, but not firefox or ie? 按钮不适用于Firefox,但适用于Chrome - Button not working in Firefox but does in Chrome 提交按钮可以在Chrome浏览器中使用,但不能在Firefox中使用? - Submit button working in Chrome but not Firefox? 提交按钮在 Chrome 中不起作用,但在 Firefox 中起作用 - Submit button not working in Chrome but working in Firefox 提交按钮可在Chrome中使用,但不能在Firefox或IE中使用 - Submit button working in Chrome but not Firefox or IE 在Firefox中,剑道按钮文本在IE和Chrome中无法更改 - In Firefox kendo button text is not changing while in IE and Chrome working 更新无法在Chrome上但在Firefox上运行的按钮的aria-checked属性 - Updating aria-checked attribute of a button not working on Chrome but on Firefox Javascript 表单验证代码适用于 FireFox 和 Chrome,但不适用于 Safari(在单选按钮上) - Javascript form validation code working on FireFox and Chrome but not on Safari (on radio button) 带有不透明范围按钮的输入范围在 Chrome 中不起作用,但在 Firefox 中不起作用 - Input Range with opaque range button isn't working in Chrome but in Firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM