我正在使用simple_form和纤薄的模板引擎,无法调用javascript函数
= f.input :name, placeholder: 'Name', label: false, input_html: {:onclick => "search()"}
错误Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' https:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
下面的代码正在调用JS,但不在上面
= f.input :name, placeholder: 'Name', label: false, input_html: {class: 'find'}
应用.js
$(document).ready(function() {
$('.find').on('click', function() {
alert("class javascript");
});
function search() {
alert("search from ready");
}
});
function search() {
alert("outer");
}
帮帮我,如何从轨道视图调用JS函数search((。
= f.input :name, placeholder: 'Name', label: false, :onclick => 'search();'
在这里,您在单击此输入字段时调用 search(( 函数:
所以你需要在JS中定义搜索函数
<script type="text/javascript">
function search(){
alert("outer");
}
</script>