这是最好的方式 [英] which is the best way

查看:56
本文介绍了这是最好的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在网格内的文本框中添加onclick方法。在这个场景中我可以绑定客户端id获取javascript方法中该网格项的值,或者可以直接将值绑定到javascript方法,这是最好的方法实施







1.绑定客户端ID并获取价值

txtbx1.attributes.add(onclick,Getvalues('txtbx1'));



如果我传递id javascript将搜索完整的html,所以性能将会更少





2.直接将价值绑定到方法

txtbx1.attributes.add( onclick,Getvalues('20'));



无需搜索直接获得价值表现会很好



我的答案是2.请建议你的答案

I need to add onclick method to textbox inside grid.In this scenerio i can bind the client id the get the value of that grid item inside javascript method or can bind directly the value to the javascript method which is the best way for implementation



1. binding the client id and getting the value
txtbx1.attributes.add("onclick","Getvalues('txtbx1')");

If i am passing id javascript will search complete html,so performance will be less


2. Bind value directly to the method
txtbx1.attributes.add("onclick","Getvalues('20')");

No need to search get the value directly performance will be good

My answer is 2 .Please suggest your answers

推荐答案

你正在以错误的方式做Option.1。您只向javascript函数发送控件ID。我认为你在那里创建对象以在匹配元素后从文本框中获取值。这就是为什么慢。



这里有更好的方式(比现有的方式)。我只是得到了价值&发送到javascript函数。

You're doing Option.1 in wrong way. You were sending only control id to javascript function. I think you're creating object there to get value from textbox after matching the element. That's why the slow.

Here better way(than existing one). I'm just getting the value & sending to javascript function.
txtbx1.attributes.add("onclick","Getvalues('" + txtbx1.Text + "')");



另外一个建议(替代方案)。

使用jQuery而不是javascript。使用点击() [ ^ ]事件可以减少代码。


One more suggestion(alternative).
Go with jQuery instead of javascript. Using Click()[^] event you could reduce the code.


这篇关于这是最好的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆