[英]Why does this code work on my test server but not on jsfiddle?
http://jsfiddle.net/KeithDickens/t2t9pvz4/19/ http://jsfiddle.net/KeithDickens/t2t9pvz4/19/
As it's written it works fine on my Intranet test server but JSFiddle it does nothing. 在编写时,它可以在我的Intranet测试服务器上正常工作,但是JSFiddle它什么也不做。 Am I missing a nuance of JSFiddle?
我是否错过了JSFiddle的细微差别?
HTML HTML
<input type="button" value="Add More" onclick="nextLine();">
<div id="test1">
Test1:<input type="text">
Test2:<input type="text">
Test3:<input type="text">
</div>
<br />
<br />
<div style="display:none" id="test2" name="test2">
Test1:<input type="text">
Test2:<input type="text">
Test3:<input type="text">
<input type="button" value="Remove">
</div>
<br />
<br />
<div style="display:none;" id="test3" name="test3">
Test1:<input type="text">
Test2:<input type="text">
Test3:<input type="text">
<input type="button" value="Remove">
</div>
JavaScript JavaScript的
var xy = 2;
var divid = "";
function nextLine() {
divid = "test" + xy;
document.getElementById(divid).style.display = 'block';
xy++;
}
Because jsFiddle is adding window.onload = function() {}
around your JS, which causes the function in your onClick attribute to no longer be in global scope. 因为jsFiddle在JS周围添加
window.onload = function() {}
,这导致onClick属性中的函数不再处于全局范围内。
If you look on the top left it does this by default. 如果您在左上方查看,则默认情况下会执行此操作。 In order for it to work you'll have to select No wrap - in
<body>
: http://jsfiddle.net/t2t9pvz4/23/ 为了使其正常工作,您必须在
<body>
选择No wrap- : http : //jsfiddle.net/t2t9pvz4/23/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.