我正在写一个表单,其中输入框有一些默认文本。当用户点击输入框时,我想要清楚哪些内容可以处理。不过,如果他们输入了超过140个字符,我也会提醒用户。但在提醒文本更改为空后再次。为了解决这个问题,我尝试设置一些标志仍然不起作用提醒后保留输入框值
这里是我的代码:
<form method="post">
<input
type="text"
maxlength="140"
name="question"
value=" What's your Question?"
onfocus="this.value = '';
this.style.color = 'black';
this.style.fontStyle = 'normal';
if(refreshFlag) {
this.value = askQues;
}"
onkeypress="if (this.value.length == this.getAttribute('maxlength')) {
var askQues = this.value;
var refreshFlag = true;
alert('Please use less than 140 characters to ask question');
this.value = askQues;
}"
style="color: black; font-style: normal;"
/>
</form>
代码也是在的jsfiddle:http://jsfiddle.net/4gQSc/
将alert.value存储到变量中并将其设置为alert后的目的是什么? – 2013-05-10 19:06:45