在JS文件中传递变量 [英] pass variable in JS file

查看:80
本文介绍了在JS文件中传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
当我需要在小部件解决方案中传递变量时,我陷入了困境.我已经建立了一个解决方案,其中可以将小部件中的明文添加到站点中.但是我需要通过向其添加ID来区分此窗口小部件,以便可以通过获取其对应于ID的记录来对其进行区别检查.
请帮我解决这个问题.在此先感谢.

Hello,
I got stuck when I need to pass a variable in a widget solution. I have build a solution where in a widget can be clearly added to site. But I need to distinguish this widget from other by adding an ID to it so that it can be checked distinctly by fetching its record corresponding to ID.
Please help me out in this. Thanks in advance.

推荐答案

您可能应该考虑使小部件成为对象.这样您就可以创建窗口小部件的多个实例.这样,每个小部件类型将仅包含1个js文件.但是您将使用它创建多个小部件.

You should probably look at making you widget an object. So that you can create multiple instances of the widget. In that way you''ll include just 1 js file per widget type. But you''ll create multiple widgets with it.

//Contents of widget.js
var widget=function(id) {
  //do your ajax thingy with the id
}



然后添加到您的页面



And then for the adding to your page

var activeWidgets=new Array();

function addWidget(someid) {
  activeWidgets[activeWidgets.length]=new widget(someeid);
}


这篇关于在JS文件中传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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