2012-11-29 23 views
0

的价值在于它可以做到在jQuery的AJAX更改DIV左对齐或右或中心

我有这样的分度,居中对齐左或右

<div class="dropdown" id="dropdown_one"> 
    <h3>Position of logo on the document</h3> 
     <input type="hidden" name="c" value="cprof" /> 
     <input type="hidden" name="user_code" value="<?=$_GET['ucom'];?>" /> 
     <input type="hidden" name="com_code" value="<?=$_GET['ccom'];?>" /> 
     <? 
     $get_position = SET_SQL("SELECT * FROM jon_com_add WHERE user_code = '".$_GET['ucom']."' "); 
     ?> 
     <input type="hidden" name="position_id" value="<?=$get_position['a_id'];?>" /> 
     <input type="hidden" name="position_change" value="chg" /> 
     <label>Logo Position : </label> 
      <p> 
      <input name="logo_position" type="radio" value="left"> 
      Left 

      <input name="logo_position" type="radio" value="center"> 
      Center 

      <input name="logo_position" type="radio" value="right"> 
      Right 
      </p> 
     <label>Logo Width</label> 
     <input type="text" name="logo_width" value="632 x 128"> 
     <p>Format logo: <span id="logo_size">632 × 128</span></p>     
</div><!-- .dropdown_menu --> 

<div class="company_name" align="<?=$set_position['add_position'];?>"> 
    <strong><?=$set['com_name'];?></strong><br /> 
    <?=$set['address'];?> 
</div> 

它已连接到数据库。

现在我的jQuery

$(function(){ 
    $('input[name=logo_position]').click(function(e) { 
     $('<img src="images/ajaxLoader.gif" id="loading" style="width:auto;" />').appendTo(".company_name"); 
     //Cancel the link behavior 
     e.preventDefault(); 
     //Get the A tag 
     var uc = $('input[name=usercode]').val(); 
     var cc = $('input[name=com_code]').val(); 
     var l_p = $('input[name=logo_position]').val(); 
     var aid = $('input[name=position_id]').val(); 
     var p_chg = $('input[name=position_change]').val(); 

     alert(aid); 
     $.ajax({ 
      type:"GET", 
      url:"forms/tem.php", 
      data: {ucode: uc, ccode: cc, logo_p: l_p, a_id: aid, chg: p_chg}, 
      dataType: 'html', 
      target: '.company_name', 
      success: function(data){ 
       $(".company_name").find('img#loading').remove(); 
       $(".company_name").html(data); 
      } 
     }) 
    }); 

}); 

什么即时试图在这里做的是,当我点击div class="company_name" align="left" logo_position 的单选按钮将发生变化。例如我点击中心它应该在中心。

是我的jQuery Ajax错? 它不会保存在数据库上,只有它保存了第一个单选按钮。但是当我点击中心时,ajax只会被读取。

就像我在做一个实时视图。所以,当我改变的东西,它也将改变位置的字体和其他东西,当我只是点击...

这是可能做的jQuery?

+0

我认为你需要解释自己这里好一点。对我来说,它只是看起来像加载你的ajax调用返回的内容到公司。公司名称 – David

+0

我认为'$('input [name = logo_position]')。val();'应该是'$('input [name = logo_position]:checked')。val();'但是这并不能解决你的问题,因为你的代码只能显示类'company_name'的div中的'tem.php'的输出,并且不会对任何对齐 – asprin

+0

'$ set_position'从哪里来? – asprin

回答

2

尝试一下本作单选按钮的div的onclick基础对齐:

$('input[name=logo_position]').click(function(e) { 

//code for changing align of div for respective button click 
$('.company_name').attr("align",$(this).val()); 

}); 

DEMO

+0

Demo @ [JSFIDDLE](http://jsfiddle.net/Nb3tp/4/) – asprin

+0

@asprin:谢谢.... :) –

+0

非常感谢... – Butternut