帮我删除此语法错误 [英] Help me to remove this syntax error

查看:97
本文介绍了帮我删除此语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想动态创建带有某些标签的复选框.我这样做了,但是遇到一些错误,请帮助消除此错误..

Hi

I want to create checkbox dynamically with some label .i done this but getting some error please help to remove this error..

<html>
<head>
<script type='text/javascript'>
function createCheckBox(){
var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = "name";
checkbox.value = "value";
checkbox.id = "id";
var label = document.createElement('label')
label.htmlFor = "id";
label.appendChild(document.createTextNode('label');
var container = document.getElementById('checkbox_here');
container.appendChild(checkbox);
container.appendChild(label);
}
</script>
</head>
<body>
<input type='button' value='Create Checkbox' onClick='createCheckBox()' />
<div id="checkbox_here"></div>
</body>
</html>

推荐答案

<html>
   <head>
   <script language="Javascript">

     function append()
     {
        var cb = document.createElement( "input" );
        cb.type = "checkbox";
        cb.id = "id";
        cb.value = "test";
        cb.checked = true;
        var text = document.createTextNode( "checkbox" );
        document.getElementById( 'append' ).appendChild( text );
        document.getElementById( 'append' ).appendChild( cb );
     }

   </script>
   </head>
<body>
   <p>click the button below</p>
   <form action="http://localhost/test.php" name="form" id="form" method="post" enctype="multipart/form-data">
   <div id="append" name="append">Append here</div>
   <input type="button" value="append" onclick="javascript:append()" />
   <input type="submit" value="submit" />
   </form>
</body>
</html>




http://bytes.com/topic/javascript/answers/701647-creating- checkboxes-dynamically-document-createelement [ ^ ]




http://bytes.com/topic/javascript/answers/701647-creating-checkboxes-dynamically-document-createelement[^]


这篇关于帮我删除此语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆