我想在提交之前设置一个必需的但是没有任何想法吗?可能超过JS?感谢您的支持
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr><td><input type="text" size"30" placeholder="Text " maxlength="10" id="source" required>
<button type="submit" class="formButton" id="submit">Submit</button></td></tr>
<tr><td height="20px"></td></tr>
<tr><td><input type="text" style="border:none" size="40" id="target" class="form69" onClick="myFunct()"></td></tr>
<tr><td height="150px"></td></tr>
<script>
$(".formButton").click(function() {
$(".form69").show();
});
</script>
<script>
$('#submit').click(function(){
var source = $('#source').val();
$('#target').val('text test' + source + ' text');
});
</script>
答案 0 :(得分:2)
您的表单字段必须位于form
元素内。
另外(仅供参考),您的每个功能都不需要单独的script
标记。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="text" size="30" placeholder="Text " maxlength="10" id="source" required>
<button type="submit" class="formButton" id="submit">Submit</button>
<input type="text" style="border:none" size="40" id="target" class="form69" onClick="myFunct()">
</form>
<script>
$(".formButton").click(function() {
$(".form69").show();
});
$('#submit').click(function(){
var source = $('#source').val();
$('#target').val('text test' + source + ' text');
});
</script>
答案 1 :(得分:1)
您没有表单标记。添加如下表单标记:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<tr><td><input type="text" size"30" placeholder="Text " maxlength="10" id="source" required>
<button type="submit" class="formButton" id="submit">Submit</button></td></tr>
</form>
<tr><td height="20px"></td></tr>
<tr><td><input type="text" style="border:none" size="40" id="target" class="form69" onClick="myFunct()"></td></tr>
<tr><td height="150px"></td></tr>
<script>
$(".formButton").click(function() {
$(".form69").show();
});
</script>
<script>
$('#submit').click(function(){
var source = $('#source').val();
$('#target').val('text test' + source + ' text');
});
</script>