在链接点击创建一个对话框,javascript [英] creating a dialog box on link click, javascript

查看:158
本文介绍了在链接点击创建一个对话框,javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击应用程序中的链接时,我想启动一个弹出窗口或对话框 - 我想在此窗口中添加一个水平滑块,因此用户可以调整显示的数据。我已经研究了各种dijit小部件,但不确定什么工作,我试图测试一些小部件,如对话框,TooltipDialog,但没有得到任何结果。我也很新的javascript,所以我的编码不是最大的。如果有人有建议,我正在寻找一些有用的样本。我尝试从dojo网站上的示例代码开始,但是还没有能够让它工作,我知道我错过了一些。



这是一个例子在下面,我只是尝试在一个按钮(从dojo站点获取的代码)之间创建一个对话框,然后测试一个链接。我不断收到错误 myDialog未定义。即使我在myDialog之前放置了 var ,我仍然收到相同的错误。

 <!DOCTYPE html> 
< html>
< head>

< link rel =stylesheethref =http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/tundra/tundra.css/ >

< script> dojoConfig = {parseOnLoad:true}< / script>
< script src =// ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js\"></script>

< script>
require([dijit / Dialog,dojo / domReady!],function(Dialog){
var myDialog = new Dialog({
title:My Dialog,
content:测试内容,
style:width:300px
});
});
< / script>
< / head>
< body class =claro>
< button onclick =myDialog.show();> show< / button>
< / body>
< / html>


解决方案

你的代码有几个错误。 p>

1)使用错误的样式。

身体标签有 claro 在您的链接标签中请求 tundra

 < body class =克拉罗> 

< link rel =stylesheethref =http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/tundra/tundra.css/ >

需要更改其中之一。

将链接标记更改为 claro stylesheet。例如

 < link rel =stylesheethref =http://ajax.googleapis.com/ajax/libs/道场/ 1.9.2 /的dijit /主题/苔原/ claro.css/> 




  1. myDialog是局部范围的。

在函数内使用 var 关键字声明的任何变量只能在功能。

  function(Dialog){
var myDialog = new Dialog({...
}

变量 myDialog 不可见
要使 myDialog 全局,您需要删除 var keyword.eg

  myDialog = new Dialog({.... 


I would like to be able to launch a popup or dialog box when clicking on a link in my application - I want to add a horizontal slider to this window so the user can adjust the data displayed. I have been researchng various dijit widgets but am unsure of what will work, I have tried to test some of the widgets like dialog, TooltipDialog but have not gotten any results. i am also very new to javascript so my coding is not the greatest. I'm looking for some useful samples if anyone has suggestions. I tried to start with the sample code on the dojo website but haven't been able to get that to work either, I know I am missing something.

Here's an example below where I am just trying to create a dialog box off a button (code taken from dojo site), before testing with a link. I keep getting the error myDialog is not defined. Even when I put var before myDialog, I still get the same error.

<!DOCTYPE html>
<html >
<head>

    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/tundra/tundra.css"/>

    <script>dojoConfig = {parseOnLoad: true}</script>
    <script src="//ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js"></script>

    <script>
require(["dijit/Dialog", "dojo/domReady!"], function(Dialog){
    var myDialog = new Dialog({
        title: "My Dialog",
        content: "Test content.",
        style: "width: 300px"
    });
});
    </script>
</head>
<body class="claro">
    <button onclick="myDialog.show();">show</button>
</body>
</html>

解决方案

There are couple of mistakes in your code.

1) Using the wrong styling.
The body tag has claro styling where as you have requested tundra in you link tag.

<body class="claro">

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/tundra/tundra.css"/>

Need to change one of them.
change link tag to claro stylesheet. e.g

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/tundra/claro.css"/>

  1. myDialog is locally scoped.

Any variable declared using a var keyword inside a function is only available within the function.

function(Dialog){
    var myDialog = new Dialog({...
}

Variable myDialog is not visible outside the function. To make myDialog global you need to remove the var keyword.e.g

myDialog = new Dialog({....

这篇关于在链接点击创建一个对话框,javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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