我正在使用Laravel集体表格。我想使用onclick analytic.js,但浏览器显示一个错误。这是代码
<div class="field-name">
{{--<%= f.text_field :name, placeholder: 'your name', :onclick => "ga('send','event', 'form-lp-input', 'step3-name', '', 0);" %>--}}
{!!Form::text('name','yes',null,['placeholder'=>'yourname','onclick'=>'ga('send', 'event', 'form-lp-input', 'step2-zip',
'', 0);'])!!}
</div>
答案 0 :(得分:0)
您的代码中有两个问题:
Form::text()
仅使用 3 参数,您正在传递 4 :public static function text($name, $value = null, $options = array())
尝试一下:
{!!Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => 'ga("send", "event", "form-lp-input", "step2-zip","", 0);'])!!}
答案 1 :(得分:0)
我看到我的回答有点迟了:)但还是,也许这种解决方案可以帮助某人...
要转义报价,可以使用\Illuminate\Support\HtmlString
class,如下所示:
{!! Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => (new \Illuminate\Support\HtmlString("ga('send', 'event', 'form-lp-input', 'step2-zip', '', 0)"))]) !!}