javascript 带有 Cakephp html 输入的 onclick
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11830042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 14:28:44 来源:igfitidea点击:
onclick with Cakephp html input
提问by learner23
I need help, I'm using CakePHP and its html helper. I need to select all in the input field when I click in the input field.
我需要帮助,我正在使用 CakePHP 及其 html 帮助程序。当我在输入字段中单击时,我需要在输入字段中选择所有内容。
JavaScript:
JavaScript:
`<script type="text/javascript">
function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}
</script>`
Php:
博士:
`<?php echo $html->input('Listing/client_name', array('size' => '15','id' => 'client_name', "onclick'=>'SelectAll('client_name');", 'value'=>'Seller Name', 'class'=> 'font_display_normal' ))?>`
回答by Guilherme Torres Castro
It's a syntax error, onclick must be a key on array.
这是一个语法错误,onclick 必须是数组上的一个键。
"onclick'=>'SelectAll('client_name');"
should be:
应该:
'onclick'=> 'SelectAll("client_name");'
try:
尝试:
`<?php echo $html->input('Listing/client_name', array('size' => '15','id' => 'client_name', 'onclick'=> 'SelectAll("client_name");' , 'value'=>'Seller Name', 'class'=> 'font_display_normal' ))?>`