Javascript 使用jQuery追加时重复输入
代码如下:Javascript 使用jQuery追加时重复输入,javascript,jquery,input,append,Javascript,Jquery,Input,Append,代码如下: <form class="ui form attached fluid loading segment" onsubmit="return contact(this)"> <div class="field"> <label>Preferred Tour</label> <div class="field">
<form class="ui form attached fluid loading segment" onsubmit="return contact(this)">
<div class="field">
<label>Preferred Tour</label>
<div class="field">
<?php
$conn=mysqli_connect('####','####','####','####');
echo '<select required id="tourInfo">';
echo '<option value="" selected disabled>--Preferred Tour--</option>';
$db = mysqli_query($conn, "SELECT `id`,`tourprice`,`tourname` FROM `available_tours`");
while ($d=mysqli_fetch_assoc($db)) {
echo "<option value=".$d['id']." id=".$d['tourname']. " data-price=".$d['tourprice'].">".$d['tourname']."</option>";
}
echo "</select>";
?>
</div>
</div>
<div class="field" id="hiddenTortu" style="display: none;">
<label>Attention</label>
<div class="ui icon">
<p><b>The minimum of people for this tour is 5, less than 5 the tour is not realisable</b></p>
</div>
</div>
<div class="field">
<label>Available Time</label>
<div class="field">
<?php
$conn=mysqli_connect('####','####','####','####');
echo '<select name="gender" required id="timeInfo">';
echo '<option value="" selected disabled>--Preferred Time--</option>';
$db = mysqli_query($conn, "SELECT `time_real` FROM `available_time`");
while ($d=mysqli_fetch_assoc($db)) {
echo "<option value=".$d['time_real'].">".$d['time_real']."</option>";
}
echo "</select>";
?>
</div>
</div>
<div class="two fields">
<div class="field" id="pax">
<label>Please specify the number of People according to the perred tour selection</label>
首选旅游
使用id pax将脚本从div内部移出,然后
在附加以下内容之前,清除id为pax的元素的html:
//Using JQuery
$('#pax').html('');
我还有一个关于同一剧本的问题。我如何禁用在输入类型编号上写入的选项,并让箭头继续工作。我尝试了这个$(“[type='number']”);但是没有用。你可以禁用它们,这可能会更容易。您的查询选择器是错误的,您需要$('input[type=“number”]).keypress()等,但您可以禁用它们,而不是覆盖按键事件,例如,$('input[type=“number”]).prop('disabled',true);它不起作用。禁用者可以执行此操作,但不允许使用箭头更改值。我需要输入允许用户仅使用箭头更改值,以根据最小值和最大值增加或减少值,并且不输入超过最小值和最大值的键入数字。@Ivargasmoya并非所有浏览器都支持输入类型=数字,它总是给他们箭头来上下移动数字。但是如果你想走那条路线,你可以在输入上设置最小值和最大值,这样当用户点击箭头时,它就不会让数字超过或低于those@Ivargasmoya加载文档后,您需要使用JQuery的document.ready()将事件侦听器附加到输入,然后在该函数中执行$('input[type])=“number”).on('keypress',函数(evt){evt.preventDefault();});
//Using JQuery
$('#pax').html('');