我有這樣如何從文本字段
'< input id="yourinput" type="text" >'
一旦用戶在HTML表單中的文本框添加刪除邊界進入它的文字和移出我想使邊框爲1個像素(這樣看起來不像普通的文本字段)。我通過
$("#searchforstatus").css("border", "1px");
現在做到這一點,當用戶回來到文本字段,我想使文本字段的樣子與它的退出值原本正常的看文本字段。
我有這樣如何從文本字段
'< input id="yourinput" type="text" >'
一旦用戶在HTML表單中的文本框添加刪除邊界進入它的文字和移出我想使邊框爲1個像素(這樣看起來不像普通的文本字段)。我通過
$("#searchforstatus").css("border", "1px");
現在做到這一點,當用戶回來到文本字段,我想使文本字段的樣子與它的退出值原本正常的看文本字段。
假設你想要的input
只神態各異當它包含一個值,我建議這樣的:
$(document).ready(
function(){
$('#textInput').blur(
function(){
if ($(this).val()) {
$(this).addClass('bordered');
}
});
$('#textInput').focus(
function(){
$(this).removeClass('bordered');
});
});
而且在定義bordered
CSS類CSS文件(而不是增加/ jQuery中與css()
除去CSS屬性),例如:
.bordered {
border: 1px solid #f00;
}
// Add border when user enters text field
$("#yourinput").focus(function() {
$(this).css("border", "1px");
});
// Remove border when user leaves text field
$("#yourinput").blur(function() {
$(this).css("border", "0");
});
做嚴格的CSS,不使用JavaScript的,那是像用錘子的主食..
<style>
#searchforstatus{
border:none;
}
#searchforstatus:focus{
border:1px solid silver;
}
</style>
OR。創建帶有border:none和border的類; 1px並隨意分配/取消分配。
這應該工作:
$("#searchforstatus").css("border", "");
它看起來像$("#searchforstatus").css("border", null)
之前1.4.3工作,但它不是以往任何時候都實際上是有效的:http://bugs.jquery.com/ticket/7233
$("#yourinput").focus(function() {
$(this).css("border", "");
}
$("yourinput").blur(function() {
if($(this).val() != "")
$(this).css("border", "1px");
}
我認爲最好的和簡單的解決方案是:
$("#searchforstatus").css("border", "none");
如果您使用jQuery Mobile的,如果你測試它的移動,你需要在你的CSS文件中添加以下代碼
textarea:focus, input:focus{
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
-webkit-user-modify: read-write-plaintext-only;
}
它正在爲我工作
可能的重複http://stackoverflow.com/questions/576319/reset-an-input-controls-border-color-html- JavaScript的 – cdhowie 2010-11-19 21:29:42