我有一个包含三个textarea的表单。如果点击了一个textarea,我想提交我的表单。
<form action="" method="post">
<div class="time">
<div class="time-control">
<div class="tcont-in">
<p>Morning</p>
<textarea name="time" id="foo" style="color: white; background-color: black; height:30px;position: absolute;left:608px" readonly>05PM-12PM</textarea>
</div>
</div>
<div class="time-control">
<div class="tcont-in">
<p>Afternoon</p>
<textarea name="time2" id="foo1" style="color: white; background-color: black; height:30px; position: absolute;left:608px" readonly>12PM-05PM</textarea>
</div>
</div>
<div class="time-control">
<div class="tcont-in">
<p>Evening</p>
<textarea name="time3" id="foo2" style="color: white; background-color: black; height:30px; position: absolute;left:608px" readonly>05PM-10PM</textarea>
</div>
</div>
</div>
<div class="check-control">
<div class="pref-checkbox">
<div class="checkbox-time">
<input type="checkbox" value="No" id="checkboxFourInput" name="Preference" checked="" />
<label for="checkboxFourInput"></label>
</div>
<h3>No Preference</h3>
</div>
</div>
<div class="">
<button type="submit" name="submit" value="submit" class="btn-next">NEXT</button>
</div>
</div>
</form>
答案 0 :(得分:2)
使用可用的submit()
函数,您可以将click
侦听器附加到textarea并运行submit()
函数。
document.getElementById("myTextAreaId").addEventListener("click", function () {
document.getElementById("myForm").submit();
});
答案 1 :(得分:0)
简单地向所有文本框添加onclick或onblur事件
像
$(document).ready(function() {
$('.textboxClass').on('change click blur keyup', submitForm);
});
function submitForm(){
$('#form').submit();
}
答案 2 :(得分:0)
试试这个:
<form>
<textarea class="messagearea">Write your message here...</textarea>
</form>
把它放在JS中:
$('.messagearea').keydown(function(event) {
if (event.keyCode == 13) {
$(this.form).submit()
return false;
}
}).focus(function(){
if(this.value == "Write your message here..."){
this.value = "";
}
}).blur(function(){
if(this.value==""){
this.value = "Write your message here...";
}
});
答案 3 :(得分:0)
如果您不介意使用JQuery,可以使用以下内容:
$('textarea[id^="foo"]').on(
'click',
function()
{
$('button[type="submit"]').trigger('click');
}
);