我用的是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>发布于 2018-11-29 16:48:29
代码中有两个问题:
Form::text()只使用3参数,您正在传递4public static function text($name, $value = null, $options = array())试试这个:
{!!Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => 'ga("send", "event", "form-lp-input", "step2-zip","", 0);'])!!}发布于 2020-08-14 15:56:40
我看到我回答得有点晚了:)但是,也许这个解决方案会帮助到某人.
要转义引号,可以使用\Illuminate\Support\HtmlString 班级,如下所示:
{!! Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => (new \Illuminate\Support\HtmlString("ga('send', 'event', 'form-lp-input', 'step2-zip', '', 0)"))]) !!}https://stackoverflow.com/questions/53543613
复制相似问题