以表单形式将onfocus添加到codeigniter数组中

发布于 2024-12-28 05:44:32 字数 402 浏览 0 评论 0原文

我想将 onfocus 命令添加到 Codeigniter 中的数组中。我通常将此代码添加到我的输入中:

onfocus="this.value=''"

我正在使用一个数组(见下文),并且需要知道如何向其中添加 onfocus(如果不能在数组中完成,那么可以在哪里完成

$login = array(
    'name'  => 'login',
    'id'    => 'login',
    'value' => set_value('login', 'Email'),
);

?对于输入:

<?php echo form_input($login); ?>

I'd like to add an onfocus command to an array in Codeigniter. I generally add this code to my inputs:

onfocus="this.value=''"

This I'm using an array (see below) and need to know how to add onfocus to it (and if it can't be done in an array, where can it be done?

$login = array(
    'name'  => 'login',
    'id'    => 'login',
    'value' => set_value('login', 'Email'),
);

and for the input:

<?php echo form_input($login); ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生生不灭 2025-01-04 05:44:32

您可以在页面加载后执行此操作,以便更好地控制页面。试试这个。

$(function(){
   //if you have a id to input element then you can use
   //id selector which is much better than attribute selector.
   $('input[name=login]').focus(function(){
       //Write your code here to do on focus
       //this.value = '';
   })
});

You can do this once the page is loaded to have a better control on it. Try this.

$(function(){
   //if you have a id to input element then you can use
   //id selector which is much better than attribute selector.
   $('input[name=login]').focus(function(){
       //Write your code here to do on focus
       //this.value = '';
   })
});
凉月流沐 2025-01-04 05:44:32

您可以将其添加为数组的另一部分:

$login = array(
    'name'  => 'login',
    'id'    => 'login',
    'value' => set_value('login', 'Email'),
    'onfocus' => "this.value=''",
);

但是请参阅@ShankarSangoli 帖子,这是管理这种情况的更好方法。

You can just add it as another part of the array:

$login = array(
    'name'  => 'login',
    'id'    => 'login',
    'value' => set_value('login', 'Email'),
    'onfocus' => "this.value=''",
);

However see @ShankarSangoli post, that’s a better way to manage the situation.

孤凫 2025-01-04 05:44:32

如果您希望表单包含一些附加数据,例如 Javascript,您可以将其作为第三个参数中的字符串传递:

 $js = 'onClick="some_function()"';

 echo form_input('username', 'johndoe', $js);

所有内容均记录在 codeigniter

希望这有帮助!

If you would like your form to contain some additional data, like Javascript, you can pass it as a string in the third parameter:

 $js = 'onClick="some_function()"';

 echo form_input('username', 'johndoe', $js);

It is all documented over at codeigniter

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文