Jquery用户控件(Jquery user control)
我有一个问题,没有在asp用户控件中加载jquery。
我只想在单击复选框时添加click事件。
这是我的javascript文件
$(document).ready(function() { var arr = jQuery(":checkbox[id*='drpAccountType']"); for (i = 0; i < arr.length; i += 1) { $("#" + arr[i].id).click(function() { alert(this.id) }); } }); if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
用户控制预渲染事件:
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender ScriptManager.RegisterClientScriptInclude(Me, Me.GetType, "CheckboxdropdownScript", ResolveUrl("~/Scripts/CheckBoxDropDown.js")) End Sub
脚本加载正常,但jQuery的任何用法都返回undefined。 然后只有在加载页面时,我才能在firebug中为commande行执行相同的代码。 jquery库加载在母版页中。
每当我在asp用户控件中使用jquery时,我总会发现问题,而且我总是不得不破解它以使其工作。 我尝试了stackoverflow中的所有条目,但我从来没有找到一个作为一般解决方案。
有没有人发现一个简单的解决方案,使用jquery与母版页,用户控制在asp.net我会很感激,如果有人可以分享这些有价值的信息。
我的经理即将从应用程序中删除jquery,因为我们总是花费大量时间来找到一个解决方法,让它与用户控件一起工作。
请帮助,我喜欢jquery,我真的想将它用于客户端脚本。
最好的祝福
I have a problem with jquery not loaded in an asp user control.
I want simply to add the click event when a checkbox is clicked.
Here is my javascript file
$(document).ready(function() { var arr = jQuery(":checkbox[id*='drpAccountType']"); for (i = 0; i < arr.length; i += 1) { $("#" + arr[i].id).click(function() { alert(this.id) }); } }); if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
The user control pre render events:
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender ScriptManager.RegisterClientScriptInclude(Me, Me.GetType, "CheckboxdropdownScript", ResolveUrl("~/Scripts/CheckBoxDropDown.js")) End Sub
the script is loaded fine but any usage of jQuery return undefined. Then only when the page is loaded I can excute the same code for the commande line in firebug. The jquery library is loaded in the master page.
Whenever I'm using jquery within an asp user control I always find problems, and I always have to hack around to get it to work. I try all the entries in stackoverflow but I never found a one as general solution.
did any one found a simple solution to use jquery with master pages, user control in asp.net I would appreciate if someone can share such valuable information.
My manager is about to drop jquery from the application as we always waist lot of time just to find a workaround to have it to work with user controls.
Please help, I like jquery and I really want to use it for client script.
best regards
原文:https://stackoverflow.com/questions/967400
最满意答案
你实际上想要做的是读一个论点。 你可以使用
process.argv
。 更多关于在这里找到的全局节点变量process
。当你的脚本标签看起来像这样:
"scripts": { "my-command": "my-script.js" }
当你的脚本文件看起来像这样:
console.log( process.argv );
然后所有要做的就是用
npm
或yarn
运行你的命令。npm run my-command <your-argument e.g. file.js>
如果您想将它传递给另一个命令,您可以使用
require( 'child_process' ).exec
.require( 'child_process' ).exec
来调用该命令。 关于这个的一个很好的例子可以在这里找到。What you actually want to do is reading an argument. You can use
process.argv
for that. More about the global node variableprocess
to be found here.When your script tag looks something like this:
"scripts": { "my-command": "my-script.js" }
When your script file looks something like this:
console.log( process.argv );
Then all is left to do is run your command with
npm
oryarn
.npm run my-command <your-argument e.g. file.js>
If you want to pass it to another command, you can call that command with a
require( 'child_process' ).exec
. A good example about that can be found here.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你实际上想要做的是读一个论点。 你可以使用process.argv 。 更多关于在这里找到的全局节点变量process 。 当你的脚本标签看起来像这样: "scripts": { "my-command": "my-script.js" } 当你的脚本文件看起来像这样: console.log( process.argv ); 然后所有要做的就是用npm或yarn运行你的命令。 npm run my-command
如果您想将它传递给另一个 ... -
代码因为执行而起作用 npm start 然后它会在'开始'配置后执行命令。 被删除的行与npm start没有任何关系。 你可以通过使用来执行它们 npm lite 然后将在精简版服务器中启动,请参阅: https ://www.npmjs.com/package/lite-server 换一种说法。 他们是启动参数。 有关更多信息,请查看: https : //docs.npmjs.com/misc/scripts The code works because you execute npm sta ...
-
你正在得到一个JSON解析错误,因为你试图解析字符串 "[object Object]" 你应该改变你的bash脚本来: node -e "console.log(JSON.parse(\`$str\`)['name'])" 注意反引号! 你的字符串是一个多行字符串。 这是一个运行(在我的一个项目目录中): $ str=`cat package.json` $ prop="name" $ myval="$(node -e "console.log(JSON.parse(\`$str\`)['$prop' ...
-
$npm_execpath环境变量引用了构建工具,因此只需将npm替换为$npm_execpath : { "test": "$npm_execpath run lint && mocha" } npm test和yarn test都能正常工作,并将使用适当的构建工具。 The $npm_execpath environment variable refers to the build tool, so just replace npm with the $npm_execpath: { "tes ...
-
控制台/终端通常支持ANSI / VT100控制序列 ,因此可以使用这些代码来控制字体颜色,字体粗细,背景颜色等。 有关仅限Bash的解决方案,请参阅下面的Bash(MacOS / Linux / etc ..)部分。 但是,如果需要跨平台支持,请遵循下面的跨平台部分中描述的解决方案。 Bash(MacOS / Linux /等..) 重要说明:以下内容无法在非bash控制台上成功运行,例如Windows命令提示符 (即cmd.exe)或PowerShell 。 这个例子是下面的npm脚本: "script ...
-
如何阻止React Webpack包含来自package.json的脚本(How to stop React Webpack from including scripts from package.json)[2022-01-26]
抖动像你这样的json文件的树需要它是webpack 4.x中的一个新特性 这是票: https://github.com/webpack/webpack/issues/5578 你可以编写一个脚本来读取版本号,并在webpack运行之前将其写入它自己的文件中,如果你必须继续使用3.x,但是希望create-react-app很快就会更新,那么可以导入它。 这里已经有一个开放的请求: https://github.com/facebook/create-react-app/pull/4077 Tree sh ... -
添加此行: "dependencies": { "jquery": "^3.1.0", "jquery-ui": "^1.12.0", "ol3-layerswitcher": "git://github.com/walkermatt/ol3-layerswitcher.git", "openlayers": "^3.17.1" } add this line : "dependencies": { "jquery": "^3.1.0", "jq ...
-
在其中一个脚本中使用package.json的version属性(Use version attribute of package.json in one of it's script)[2021-12-16]
你可以这样做: "build-js": "browserify -t [ babelify --presets [ react es2015 ] ] js/components/App.js -o js/bundle.$npm_package_version.js" 有关详细信息,请参阅此视频: https : //egghead.io/lessons/tools-use-custom-config-settings-in-your-npm-scripts PS值得将你的软件包放在与你的源相同的目录中,通 ...