Twitter Bootstrap Radio Toggle - 适用于IE9以外的所有浏览器

时间:2012-11-14 06:41:51

标签: javascript twitter-bootstrap radio-button internet-explorer-9

使用twitter bootstrap的一些单选按钮,这个例子中的html和js工作得很好:

<div class="btn-group" data-toggle="buttons-radio" >
  <button type="button" class="btn" data-toggle="button">
    Public
    <input type="radio" name="is_private" value="0" />
  </button>
  <button type="button" class="btn" data-toggle="button">
    Private
    <input type="radio" name="is_private" value="1" />
  </button>
</div>​


$('div.btn-group button').click(function(){
    alert($(this).children('input[name="is_private"]').val());
})​

http://jsfiddle.net/XYEjs/31/

问题是我无法在IE9中使这个例子(或我的代码)工作。它不返回值,而是返回'undefined'。

此示例似乎在所有其他浏览器(或至少我尝试过的所有浏览器...... Chrome,Safari,Firefox)中正常工作(意味着它返回html中指定的值)......甚至可以在IE8中运行和IE10。

它在IE9中无效。思考?

提前致谢...

1 个答案:

答案 0 :(得分:0)

也许这有点晚了,但我刚遇到同样的问题。问题是IE9显然不喜欢按钮内的输入。我刚刚用s替换按钮,它的工作原理。花了一整天的时间来处理那件蠢事。

public class ListViewAdapter extends BaseAdapter {

    // Declare Variables
    Context context;
    LayoutInflater inflater;
    ArrayList<HashMap<String, String>> data;
    ImageLoader imageLoader;
    private List<WorldPopulation> worldpopulationlist = null;
    private ArrayList<WorldPopulation> arraylist;

    public ListViewAdapter(Context context,
            List<WorldPopulation> worldpopulationlist) {
        this.context = context;
        this.worldpopulationlist = worldpopulationlist;
        inflater = LayoutInflater.from(context);
        this.arraylist = new ArrayList<WorldPopulation>();
        this.arraylist.addAll(worldpopulationlist);
        imageLoader = new ImageLoader(context);
    }

    public class ViewHolder {

        TextView word;

    }

    @Override
    public int getCount() {
        return worldpopulationlist.size();
    }

    @Override
    public Object getItem(int position) {
        return worldpopulationlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public View getView(final int position, View view, ViewGroup parent) {
        final ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.listview_item, null);
            // Locate the TextViews in listview_item.xml

            holder.word = (TextView) view.findViewById(R.id.word);

            // Locate the ImageView in listview_item.xml

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        // Set the results into TextViews

        holder.word.setText(worldpopulationlist.get(position).getWord());

        // Set the results into ImageView

        // Listen for ListView Item Click
        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // Send single item click data to SingleItemView Class
                Intent intent = new Intent(context, SingleItemView.class);
                // Pass all data definition

                intent.putExtra("definition",
                        (worldpopulationlist.get(position).getDefinition()));
                // Pass all data word
                intent.putExtra("word",
                        (worldpopulationlist.get(position).getWord()));
                                // Pass all data flag
                intent.putExtra("flag",
                        (worldpopulationlist.get(position).getFlag()));
                // Start SingleItemView Class
                context.startActivity(intent);
            }
        });
        return view;
    }

    // Filter Class
    public void filter(String charText) {
        charText = charText.toLowerCase(Locale.getDefault());
        worldpopulationlist.clear();
        if (charText.length() == 0) {
            worldpopulationlist.addAll(arraylist);
        } else {
            for (WorldPopulation wp : arraylist) {
                if (wp.getWord().toLowerCase(Locale.getDefault())
                        .contains(charText)) {
                    worldpopulationlist.add(wp);
                }
            }
        }
        notifyDataSetChanged();
    }
}