我有一个文本框,其中包含文本值以及onfocus和onblur函数,这些函数会使文本消失并在单击或关闭时显示...
附加到文本框的onblur和onfocus函数是......
function feedbackTextBoxFocus(textFieldObject, initialText) {
if (textFieldObject) {
if (textFieldObject.value == initialText)
textFieldObject.value = '';
}
}
function feedbackTextBoxBlur(textFieldObject, initialText) {
if (textFieldObject) {
if (textFieldObject.value == '')
textFieldObject.value = initialText;
}
}
文本框是......
<asp:TextBox ID="TxtAskQuestionTitle" runat="server" CssClass="KBTopQuestionTitleTextbox" Text="Ask a question on this topic..." onblur="feedbackTextBoxBlur(this,'Ask a question on this topic...')" onfocus="feedbackTextBoxFocus(this,'Ask a question on this topic...')" />
我想通过jquery方法做什么,当点击文本框时,内容区域向下滑动,是改变文本框中的文本,并将onblur和onfocus值更改为“提供标题对于你的问题......“
$(function () {
$('.QuestionContentExpandClick').click(function () {
/**** Slide the content div ****/
var viewContent = $('#DivExpandQuestionContentArea');
viewContent.slideDown('slow', function () {
// If logged in and sliding the content area down
// the title box message changes
var titleTextbox = $('#TxtAskQuestionTitle');
titleTextbox.val('Provide a title for your question...');
//titleTextbox.attr('onfocus', feedbackTextBoxFocus(this,'Provide a title for your question...'));
//titleTextbox.attr('onblur', feedbackTextBoxBlur(this, 'Provide a title for your question...'));
});
});
});
正如您所看到的,我能够更改文本框中的文本值但无法找到更改onblur和onfocus功能的方法,有人可以帮我解决这个问题吗?非常感谢提前!
答案 0 :(得分:1)
如果在放置回调函数时使用括号,则表示您没有传递引用,而是执行该函数。此外,您只想使用.focus()
和.blur()
函数。试试这样:
titleTextbox.focus(function() {
feedbackTextBoxFocus(this,'Provide a title for your question...');
});
titleTextbox.blur(function() {
feedbackTextBoxBlur(this, 'Provide a title for your question...');
});