如何在webbrowser上运行java脚本函数 [英] How to run a java script function on webbrowser

查看:185
本文介绍了如何在webbrowser上运行java脚本函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该网站的来源:

this source of the site:

function __submit(action)
{
	document.forms[0].comboChange.value=action;
        document.forms[0].submit();
}











一个

两个

















我创建一个项目并访问此网页并设置组合框的值.after set value应该运行javascrript函数__submit('1或2')但是a不能执行这个。

请帮我执行这个。



我尝试过:



我想用输入参数运行一个javascript函数。






one
two




three
four


I make a project and visit this webpage and set value of the combobox.after set value should run javascrript function __submit('1 or 2')but a can not execute this.
please help me to execute this.

What I have tried:

I want run a javascript function with input parameter.

推荐答案

您好,



我不知道,您是如何访问该页面的。

我会建议2解决这个问题。



第一个解决方案:



你只使用html和javascript。 />
在body标签的onload事件中,在组合框中调用函数set set value,然后在函数之后调用此值。



Hi,

As I do not know, how you visit the page.
I will propose 2 solution to this problem.

First Solution:

You use only html and javascript.
In the onload event of the body tag you call the function for set value in your combobox and after the function for process this value.

<!DOCTYPE html>
<html>
    <head>
        <title>Run JS</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script>
            function _submit()
            {
                var e = document.getElementById("ddlView");
                var id = e.options[e.selectedIndex].value;
                
                alert('Value selected is: ' + id); 
                
            }
            
            function visit()
            {
                document.getElementById("ddlView").value = '1'; 
            }
        </script>
    </head>
    <body onload="visit();_submit();">
        <div>
            <select id="ddlView">
                <option value="0" selected="selected">Select one item</option>
                <option value="1">Item 1</option>
                <option value="2">Item 2</option>
                <option value="3">Item 3</option>
                <option value="4">Item 4</option>
            </select>
            
        </div>
    </body>
</html>


第二种解决方案



你使用html,javascript和C#。



在html代码中,您将使用该按钮调用该函数来处理该值。

此按钮将被隐藏。



Second Solution

You use html, javascript e C#.

In the html code, you will use the button to call the function to process the value.
This button will be hidden.

function _submit() 
{
    var e = document.getElementById("combobox");
    var id = e.options[e.selectedIndex].value;
    alert('Value selected is: ' + id);
}




<div>
        <asp:DropDownList ID="combobox" runat="server">
            <asp:ListItem Text="Item 1" Value="1"></asp:ListItem>
            <asp:ListItem Text="Item 2" Value="2"></asp:ListItem>
            <asp:ListItem Text="Item 3" Value="3"></asp:ListItem>
            <asp:ListItem Text="Item 4" Value="4"></asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="btnOCRunScript" style="visibility:hidden;"  runat="server" OnClientClick="_submit();" Text="RodarScript" />
    </div>





在代码隐藏中,在页面加载事件中,您设置了值,并且然后注册脚本以动态点击html页面上的按钮。





In the code-behind, in the page load event, you set the value, and then register the script to dynamically click the button on the html page.

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //set the item 3. value 3 
                this.combobox.SelectedIndex = 2;

                //script for click in button dynamically 
                string script = "document.getElementById(\"btnOCRunScript\").click();";

                //register script in html
                // Check to see if the startup script is already registered.
                if (!this.Page.ClientScript.IsStartupScriptRegistered(this.GetType(), "runbutton"))
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "runbutton",script, true);
                }
            }
        }


这篇关于如何在webbrowser上运行java脚本函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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