有html表单代码,将其写入laravel,转换为this.value ==''进入this.value ==#039;怎么写这个.value ==''在laravel?
<input class="form-control select-design" required value="Years of Work Experience" name="experience" type="text" required onblur="if(this.value==''){ this.value='Years of Work Experience'; this.style.color='#BBB';}" onfocus="if(this.value=='Years of Work Experience'){ this.value=''; this.style.color='#000';}" style="color:#BBB;">
将其写入laravel(php)
{!! Form::text('experience', null, ['class' => 'form-control select-design','value' => 'Years of Work Experience','name'=>"experience",'type'=>"text",'onblur'=>"if(this.value==''){ this.value='Years of Work Experience'; this.style.color='#BBB';}",'onfocus' => "if(this.value=='Years of Work Experience'){ this.value=''; this.style.color='#000';}",'style'=>"color:#BBB;"]) !!}
它显示了像这样的实际代码
<input class="form-control select-design" name="experience" type="text" onblur="if(this.value==''){ this.value='Years of Work Experience'; this.style.color='#BBB';}" onfocus="if(this.value=='Years of Work Experience'){ this.value=''; this.style.color='#000';}" style="color:#BBB;">
语法有问题吗?
答案 0 :(得分:0)
您无法在Form::text()
中执行此操作,因为它正在使用htmlspecialchars()
功能,您无法更改它。你能做的是create custom macro。但我仍然认为将JS函数硬编码到Laravel Collective表单中是个糟糕的主意。
您可以做的最好的事情是将所有JS逻辑移动到JS文件并执行以下操作:
$("#element").blur(....);
或者您可以使用简单的HTML表单。但是将所有JS逻辑从HTML中移出是最佳选择。