Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript或jquery进行验证_Javascript_Textbox - Fatal编程技术网

使用javascript或jquery进行验证

使用javascript或jquery进行验证,javascript,textbox,Javascript,Textbox,如何在单击“添加”按钮时动态创建文本框 在我将输入字段放入文本框之后 如何使用javascript或jquery验证动态创建的文本框 <html> <head> <title>Adding and Removing Text Boxes Dynamically</title> <script type="text/javascript"> var intTextBox=0; //FUNCTION TO ADD TEXT BOX ELE

如何在单击“添加”按钮时动态创建文本框

在我将输入字段放入文本框之后

如何使用javascript或jquery验证动态创建的文本框

<html>
<head>
<title>Adding and Removing Text Boxes Dynamically</title>

<script type="text/javascript">
var intTextBox=0;
//FUNCTION TO ADD TEXT BOX ELEMENT 
function addElement(){
  intTextBox = intTextBox + 1;
  var contentID = document.getElementById('content');
  var newTBDiv = document.createElement('div');
  newTBDiv.setAttribute('id','strText'+intTextBox);
  newTBDiv.innerHTML = "Text "+intTextBox+": <input type='text' id='" + intTextBox + "'    name='" + intTextBox + "'/>"; 
  contentID.appendChild(newTBDiv);
}

  </head>
  <body>
    <p>Demo of Adding and Removing Text Box Dynamically using JavaScript</p>
    <p><a href="javascript:addElement();" >Add</a> 
       <a href="javascript:removeElement();" >Remove</a>
    </p>
    <div id="content"></div>
    <input type="button" value="submit"/>
  </body>
  </html>

动态添加和删除文本框
var intTextBox=0;
//用于添加文本框元素的函数
函数addElement(){
intTextBox=intTextBox+1;
var contentID=document.getElementById('content');
var newTBDiv=document.createElement('div');
newTBDiv.setAttribute('id','strText'+intTextBox);
newTBDiv.innerHTML=“Text”+intTextBox+”:”;
contentID.appendChild(newTBDiv);
}
使用JavaScript动态添加和删除文本框的演示

单击“提交”按钮后,必须完成所有文本框验证…

创建文本框:

var textbox = $('<input></input>');
textbox.setAttr(type, 'text');
验证:

$('#submit').onclick(function() {
   if(!$('#textbox').val()) {
      alert('input empty');
   }
});
创建文本框:

var textbox = $('<input></input>');
textbox.setAttr(type, 'text');
验证:

$('#submit').onclick(function() {
   if(!$('#textbox').val()) {
      alert('input empty');
   }
});

你可以用这个。显示可以验证文本框。

您可以使用它。显示可以验证文本框。

这是一个包含大量问题的显示。您可以使用如下代码在jquery中创建和插入元素:

$('<input />', {type : 'text'}).appendTo($(body));
但是,如果需要特定于您创建的字段,您也可以在创建元素时附加验证

$('<input />', {type : 'text'}).bind('keyup', function(){ 
    /*Do stuff*/
}).appendTo($(body));
$('',{type:'text'}).bind('keyup',function(){
/*做事*/
})。附于($(正文));

我希望这能引导你朝着正确的方向前进。祝你好运

这是一堆问题。您可以使用如下代码在jquery中创建和插入元素:

$('<input />', {type : 'text'}).appendTo($(body));
但是,如果需要特定于您创建的字段,您也可以在创建元素时附加验证

$('<input />', {type : 'text'}).bind('keyup', function(){ 
    /*Do stuff*/
}).appendTo($(body));
$('',{type:'text'}).bind('keyup',function(){
/*做事*/
})。附于($(正文));

我希望这能引导你朝着正确的方向前进。祝你好运,试着复制并测试一下。让我们告诉我这是您需要的。

<!DOCTYPE HTML>
<html>
<head>
<title>Adding and Removing Text Boxes Dynamically</title>

<script type="text/javascript">
var intTextBox = 0 ;//FUNCTION TO ADD TEXT BOX ELEMENT 
function addElement(){
    intTextBox += 1
  var contentID = document.getElementById('content');
  var newTBDiv = document.createElement('div');
  newTBDiv.setAttribute('id','strText'+intTextBox);
  newTBDiv.innerHTML = "Text "+intTextBox%x+": <input type='text' id='%2+ intTextBox + "'    name='" + intTextBox + "' />"; 
  contentID.appendChild(newTBDiv);
}

function removeElement(){
    var element = document.getElementById("strText"+intTextBox);
    console.log(element);
    while (element.firstChild) {
        element.removeChild(element.firstChild);
    }
    intTextBox -=1;
}
</script>
</head><body>
<p>Demo of Adding and Removing Text Box Dynamically using JavaScript</p>
<p><a href="javascript:addElement()" >Add</a> 
   <a href="javascript:removeElement();" >Remove</a>
</p>
<div id="content"></div>
<input type="button" value="submit"/>
</body>
</html>

动态添加和删除文本框
var intTextBox=0//用于添加文本框元素的函数
函数addElement(){
intTextBox+=1
var contentID=document.getElementById('content');
var newTBDiv=document.createElement('div');
newTBDiv.setAttribute('id','strText'+intTextBox);
newTBDiv.innerHTML=“Text”+intTextBox%x+:”;
contentID.appendChild(newTBDiv);
}
函数removeElement(){
var元素=document.getElementById(“strText”+intTextBox);
控制台日志(元素);
while(element.firstChild){
element.removeChild(element.firstChild);
}
intTextBox-=1;
}
使用JavaScript动态添加和删除文本框的演示

更多信息请访问


注意:使用FireFox和Chrome时,请尝试复制并测试。让我们告诉我这是您需要的。

<!DOCTYPE HTML>
<html>
<head>
<title>Adding and Removing Text Boxes Dynamically</title>

<script type="text/javascript">
var intTextBox = 0 ;//FUNCTION TO ADD TEXT BOX ELEMENT 
function addElement(){
    intTextBox += 1
  var contentID = document.getElementById('content');
  var newTBDiv = document.createElement('div');
  newTBDiv.setAttribute('id','strText'+intTextBox);
  newTBDiv.innerHTML = "Text "+intTextBox%x+": <input type='text' id='%2+ intTextBox + "'    name='" + intTextBox + "' />"; 
  contentID.appendChild(newTBDiv);
}

function removeElement(){
    var element = document.getElementById("strText"+intTextBox);
    console.log(element);
    while (element.firstChild) {
        element.removeChild(element.firstChild);
    }
    intTextBox -=1;
}
</script>
</head><body>
<p>Demo of Adding and Removing Text Box Dynamically using JavaScript</p>
<p><a href="javascript:addElement()" >Add</a> 
   <a href="javascript:removeElement();" >Remove</a>
</p>
<div id="content"></div>
<input type="button" value="submit"/>
</body>
</html>

动态添加和删除文本框
var intTextBox=0//用于添加文本框元素的函数
函数addElement(){
intTextBox+=1
var contentID=document.getElementById('content');
var newTBDiv=document.createElement('div');
newTBDiv.setAttribute('id','strText'+intTextBox);
newTBDiv.innerHTML=“Text”+intTextBox%x+:”;
contentID.appendChild(newTBDiv);
}
函数removeElement(){
var元素=document.getElementById(“strText”+intTextBox);
控制台日志(元素);
while(element.firstChild){
element.removeChild(element.firstChild);
}
intTextBox-=1;
}
使用JavaScript动态添加和删除文本框的演示

更多信息请访问


注意:使用FireFox和Chrome

您所说的“验证文本框”是什么意思?检查它是否存在?验证用户添加到其中的输入?“动态创建文本框-在发生什么事件时动态创建”是什么意思?是的,验证动态创建的文本框…可能吗?当然,在创建文本框时,为其分配ID,然后使用getElementById()确保它存在动态意味着当我单击“添加”按钮时,添加到表单中的文本框…您所说的“验证文本框”是什么意思?检查它是否存在?验证用户添加到其中的输入?您所说的“验证文本框”是什么意思动态创建文本框-发生什么事件时动态创建?是验证动态创建的文本框。。。。有可能吗?当然,当您创建文本框时,请为其分配ID,然后使用getElementById()确保其存在。动态地说,当我单击“添加”按钮时,文本框将添加到表单中……这仅用于单个文本框。。但我要求动态创建文本框验证..函数addElement(){intTextBox=intTextBox+1;var contentID=document.getElementById('content');var newTBDiv=document.createElement('div');newTBDiv.setAttribute('id','strText'+intTextBox');newtbiv.innerHTML=“text”+intTextBox+”:“contentID.appendChild(newTBDiv);}这仅用于单个文本框。。但我要求动态创建文本框验证..函数addElement(){intTextBox=intTextBox+1;var contentID=document.getElementById('content');var newTBDiv=document.createElement('div');newTBDiv.setAttribute('id','strText'+intTextBox');newtbiv.innerHTML=“text”+intTextBox+”:“contentID.appendChild(newTBDiv);}函数addElement(){intTextBox=intTextBox+1;var contentID=document.getElementById('content');var newTBDiv=document.createElement('div');newTBDiv.setAttribute('id','strText'+intTextBox');newTBDiv.innerHTML=“Text”+intTextBox+”:“contentID.appendChild(newTBDiv);}函数addSense(sense){comment.content+=sense;}函数addElement(){intTextBox=intTextBox+1;var contentID=document.getElementById('content');var newTBDiv=document.createElement('div');newTBDiv.setAttribute('id','strText'+intTextBox');newTBDiv.innerHTML=“Text”+intTextBox+”:“contentID.appendChild(newTBDiv);}函数addSense(sense){comment.content+=sense;}