1
작업중인이 양식에 문제가 있습니다. 페이지를 추가하거나 새로 고칠 때마다 값이 그대로 유지됩니다. 나는 이것이 clone 메서드가 textBox로부터 value 속성을 복사하기 때문이라고 생각한다. 다른 textBox를 추가 할 때 제거 할 수있는 방법이 있습니까?jQuery에서 clone 메소드를 사용할 때 textBox의 Value 속성을 제거하는 중
<html>
<head>
<title>JQuery Example</title>
<script type="text/javascript" src="jquery-1.4.js"></script>
<script type="text/javascript">
function removeTextBox()
{
var childCount = $('p').size() //keep track of paragraph childnodes
//this is because there should always be 2 p be tags the user shouldn't remove the first one
if(childCount != 2)
{
var $textBox = $('#textBox')
$textBox.detach()
}
}
function addTextBox()
{
var $textBox = $('#textBox')
var $clonedTextBox = $textBox.clone()
//document.getElementById('textBox').setAttribute('value', "")
$textBox.after($clonedTextBox)
}
</script>
</head>
<body>
<form id =
method="POST"
action="http://cs.harding.edu/gfoust/cgi-bin/show">
<p id= "textBox">
Email:
<input type = "text" name="email" />
<input type ="button" value ="X" onclick = "removeTextBox()"/>
</p>
<p>
<a href="javascript:addTextBox()">Add another email</a>
</p>
<input type="submit" value="submit"/>
</form>
</body>
</html>
을가 clonedTextBox $해야 코드의 두 번째 줄에 var에 이름을 – ProxyProtocol
작동하지 않습니다 아니, 내가 함께 JS 현지 바르를 시작 생각하지만, $는 나쁜 습관이고 특히 jQuery와 함께 사용할 때 혼란 스럽다. – tfwright