0

連絡先ページにフォームがあり、3 つのリンクがホームページに 1 つ、2 つ、3 つあると仮定し、各リンクの連絡先ページにリンクしたいのですが、1 つのオプションで 1 つを選択し、2 つのオプションで 1 つを選択する必要があります2など。

<select id="message_type" name="message_type" class="inputbox">
    <option value="one">Suggestion</option>
    <option value="two">Inquiry</option>
    <option value="three">Offer</option>
</select>

リンク1がクリックされると、連絡先ページにオプションが選択されたものなどが表示されます。

どうやってやるの?


編集

ホームページに3つのリンクがあります

<a href="contact.php" id="one">one</a>
<a href="contact.php" id="two">two</a>
<a href="contact.php" id="three">three</a>

今度は、リンク 1 などのオプションが選択された連絡先ページを表示したいと思います...


選択結果のコードは次のとおりです

<?php 
function dropdown($active){
$dropdown=array(
                'option1'=>'Suggestion','option2'=>'Inquiry','option3'=>'Offers'
                );

foreach($dropdown as $key=>$val){
$array[]=JHtml::_('select.option',$val,$key);
}
$dropdown  = JHtml::_('select.genericlist',$array,'message_type','class="inputbox"','text','value',$active);
return $dropdown;
}
?>

そして形で

<form name="feedback" id="frmfeedback" action=""  method="post" >
<div>
<label for="msg">Message Type: </label><span class="input"><?php echo dropdown(isset($post['message_type'])?$post['message_type']:'');?> </span>
</div>
.......
4

2 に答える 2

1

ホームページのリンクにハッシュを入れることができます:

<a href="contact.html#one">Make a Suggestion</a>

次に、連絡先ページで:

$(function(){
    var opts=['one','two','three'];
    var hash =location.hash;// use browser location object to get hash
    if(hash && hash !='#'){
      hash= hash.replace('#','');
      /* get index of hash from array*/
      var optIndex= $.inArray(hash,opts);
       /* if not in array value will be empty string, otherwise value of hash*/
      $('#message_type').val( optIndx !=-1 ? hash : '' );
    }
});

編集:問題に示されているように、IDがリンクの値と同じである場合

次を使用して、ホームページの href にハッシュを追加できます。

$('#one,#two,#three').attr('href',function(idx, oldHref){
     return oldHref +'#' + this.id;
});

EDIT:itemIdURLのクエリ文字列で使用:

$(function(){
     var opts=['477','478','479']; /* not sure these are accurate*/
    var a = document.createElement('a');
    a.href = location.href;
    var ret = {},
        seg = a.search.replace(/^\?/, '').split('&'),
        len = seg.length,
        i = 0,
        s;
    for (; i < len; i++) {
        if (!seg[i]) {
            continue;
        }
        s = seg[i].split('=');
        ret[s[0]] = s[1];
    }
    var currVal=ret['itemId'];
    if( currVal !=undefined && $.inArray(currVal,opts)>-i){
        $('#message_type').val( currVal);
    }

})
于 2013-10-30T03:22:45.320 に答える
0

異なるページの場合

var url= document.URL;
switch(url)
{
    case 'http://jsfiddle.net/bs8dp/':
        $('#message_type').val('one');
        break;

     case 'http://jsfiddle.net/bs66p/':
        $('#message_type').val('one');
        break;

     default:
           $('#message_type').val('two');



}

jsfiddle

また

同じページにオプションがある場合

('#your_tab_one').click(function(){

   $('#message_type').val('one');

});

('#your_tab_two').click(function(){

   $('#message_type').val('two');

});

('#your_tab_three').click(function(){

   $('#message_type').val('three');

});
于 2013-10-30T03:02:21.817 に答える