【问题标题】:Function parameters not working函数参数不起作用
【发布时间】:2014-05-27 06:58:16
【问题描述】:

我仍处于 javascript 的学习阶段,所以我希望有一个简单的解决方法。

我有一个图像地图区域,它将在点击时运行 javascript 函数。

这是我所拥有的:

区域映射的相关 HTML:

<img id="imageMaps" src="images/20keys.jpg" usemap="#20Keys" width="100%" alt="Select Key" border="0"/>
<map id="20keys" name="20keys">
    <area shape="circle" alt="Key 1" title="Key 1" coords="42,54,32" href="#" name="key1area" onclick="keySelected(1);"/>
</map>

目标片段的相关 HTML:

<div data-role="dialog" id="keyPopup" data-theme="b">

    <div data-role="header">
        <h1 id="keyHeader"><!--Key Description Here --></h1>
    </div> <!-- /header -->

    <div data-role="content">
        <p><a id="summaryButton" href="#pdfReader" data-role="button" data-ajax="false" onclick="pdfSelected('summary');">Summary of Key <!--Key Number Here --></a></p>
        <p><a id="manualButton" href="#pdfReader" data-role="button" data-ajax="false" onclick="pdfSelected('manual');">View Key <!--Key Number Here --> Manual</a></p>
        <p><a id="interactionsButton" href="#pdfReader" data-role="button" data-ajax="false" onclick="pdfSelected('interactions');">Interaction of Key <!--Key Number Here --> with Other Keys</a></p>
    </div> <!-- /content -->

    <div data-role="footer">

        <p class="margin">
            <a href="#home" data-rel="back" data-role="button" data-inline="true" data-icon="back">Back</a>
        </p>

    </div> <!-- /footer -->
</div> <!-- /#keyPopup -->

相关的Javascript:

var keyNumber = 0;

function keySelected(key) {
    keyNumber = key;
    //Alert 1
    if (keyNumber === 1) {
        document.getElementbyId('keyHeader').innerHTML = 'Key 1 - Description';
        document.getElementbyId('summaryButton').innerHTML = 'Summary of Key 1';
        document.getElementbyId('manualButton').innerHTML = 'Manual of Key 1';
        document.getElementbyId('interactionsButton').innerHtml = 'Interaction of Key 1 with Other Keys';
            //Alert 2
    }
}

如果我包含window.alert("test");@“//Alert 1”,它将运行但不在“Alert 2”,关于如何使其正常运行的任何想法?

如果我泄露了任何可能与此有关的重要细节,请告诉我。谢谢...

【问题讨论】:

  • 据我所知,如果js函数在第一页,你不能访问里面另一个页面的元素,如果js函数在另一个html页面,你可以'不从当前页面触发该功能..
  • 您同时启用了 href 和 onClick。还没试过,但this link 可能会有所帮助。
  • @TJ,第二页和第一页在同一个html文档中
  • href 是 onclick 事件,但您可以将 onclick 嵌入到 href
  • @Placedolders_in_use,你会怎么做?

标签: javascript html function onclick innerhtml


【解决方案1】:

我没有简单的问题......

document.getElementByID()

对不起……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-26
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多