我正在使用占位符进行文本输入,这很好.但我也想为我的选择框使用占位符.当然我可以使用这段代码:
<select>
<option value="">Select your option</option>
<option value="hurr">Durr</option>
</select>
Run Code Online (Sandbox Code Playgroud)
但是"选择你的选项"是黑色而不是光线.所以我的解决方案可能是基于CSS的.jQuery也很好.
这只会使下拉列表中的选项变为灰色(因此点击箭头后):
option:first {
color: #999;
}
Run Code Online (Sandbox Code Playgroud)
编辑:问题是:人们如何在选择框中创建占位符?但它已经得到了回答,欢呼.
使用此选项会导致所选值始终为灰色(即使选择了实际选项后):
select {
color: #999;
}
Run Code Online (Sandbox Code Playgroud) 如果单击"提交"按钮,输入字段的值为空,如何使用JQUERY显示警报?
<input type="text" id="myMessage" name="shoutbox_msg" size="16" class="field_nosize" maxlength="150">
<input id="submit" type="submit" name="submit_post" class="button_nosize" value="Senden" onclick="sendMessage(); clearInput();">
Run Code Online (Sandbox Code Playgroud) 我试图检查变量的值是否为空,但它不起作用。我还必须停止脚本并且不要插入行
网页
<input type="text" name="for_intitule" id="form_intitule">
Run Code Online (Sandbox Code Playgroud)
jQuery
var form_intitule = $('input[name=form_intitule]').val();
if(form_intitule == null){
alert('fill the blank');
return false;
}
Run Code Online (Sandbox Code Playgroud)
更新 :
$('#insertForm').on('click', function(){
var form_intitule = $('input[name=form_intitule]').val();
if($('input[name=form_intitule]').val().trim().length == 0){
alert('fill the blank');
}
$.ajax({
type: "GET",
url: "lib/function.php?insertForm="+insertForm+"&form_intitule="+form_intitule,
dataType : "html",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + '--' + textStatus + '--' + errorThrown);
},
success:function(data){
}
});
});
Run Code Online (Sandbox Code Playgroud) 如果字段为空并且图像src也是如何隐藏html中的字段.使用java脚本.请建议
<div id="pagewrapper" >
<div class="row" >
<div class="column-half" style="width:500px">
<div class="containerdiv" >
<form:label path="file4Desc" type="text" value="" maxlength="50">
</form:label>
<form:input path="file4Desc" value="${agreement.file4Desc}"
style="width:300px"/>
<font color="red"><form:errors path="file4Desc" /></font>
</div>
</div>
<div class="column-half" style="width:13%">
<div class="containerdiv">
<form:label path="filename3" type="text" value="" maxlength="50">
</form:label>
<a href="${pageContext.request.contextPath}/customer/viewDownload3/${agreement.agreementId}.htm">
<img src="${pageContext.request.contextPath}/resources/images/download3.gif"
border="0"
title="Download this document"/>
</a>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) jquery ×3
html ×2
javascript ×2
css ×1
forms ×1
html-select ×1
placeholder ×1
submit ×1
validation ×1