0

I have the following code for creating a simple drop down nav. However, this is based on if a value is selected and the GO button will take the user to the link. I would like to put an if/else statement so if no value is selected, GO button will default to 1st link.

<script>
    function sendURL(url,obj) {
        document.getElementById("urlhidden").value = url;
        jQuery('.current').html(obj.parentNode.innerHTML);
    }
    function submitURL() {
        document.location = document.getElementById("urlhidden").value;
    }
</script>


<form name="navigate" class="select">
    <ul>
        <input type="hidden" name="urlhidden" id="urlhidden" />                 
        <li>
            <a href="javascript:void(0);" onclick="javascript:sendURL('<?php $link = $GLOBALS['base_url'] . '/node/';echo $link?>4',this)">link1</a>
        </li>
        <li>
            <a href="javascript:void(0);" onclick="javascript:sendURL('<?php $link = $GLOBALS['base_url'] . '/node/';echo $link?>5',this)">link2</a>
        </li>
    </ul>
    <div class="btnHolderInline">
        <input type="button" value="Go" onclick="javascript:submitURL();"/>
    </div>
</form>
4

1 回答 1

0

对我来说,它看起来不是很“简单”。“传统”下拉导航有什么问题?

<form action="javascript:location.href=this.page.options[this.page.selectedIndex].value">
    <select name="page">
        <option value="somepage.php">link1</option>
        <option value="otherpage.php">link2</option>
    </select>
    <input type="submit" value="Go" />
</form>

除此之外,原始代码的问题在于您似乎没有任何.current元素。你真正想要的是这样的:

function submitURL() {
    $(this).parent("form").find("a:eq(0)").click();
}
于 2013-03-18T22:26:22.707 回答