首页 \ 问答 \ 输入收音机通过按钮,视觉切换行为(input-radios via buttons, visual toggling behavior)

输入收音机通过按钮,视觉切换行为(input-radios via buttons, visual toggling behavior)

我正在使用下面的代码来模拟带按钮的输入收音机:

<input id="blah" name="blah" type="hidden" value="true">
<div class="btn-group" data-toggle="buttons-radio">
   <button type=button data-toggle=button class="btn btn-primary" onClick="$('#blah').val(true);">Option1</button>
   <button type=button data-toggle=button class="btn btn-primary" onClick="$('#blah').val(false);">Option2</button>
</div>

它完美的工作,但有一个小问题。 我无法设置默认选项。 如果我将class =“btn btn-primary”更改为class =“btn btn-primary active”(假设选择1(视觉上区分为默认值)),那么按钮的视觉外观切换不再起作用,即一次我点击相反的按钮,他们都保持视觉活跃。

问题是可视化的,内部隐藏字段设置正确,没有问题。

如何在不中断切换视觉行为的情况下以可视方式制作任何按钮?


I'm using the following code to simulate input-radios with buttons :

<input id="blah" name="blah" type="hidden" value="true">
<div class="btn-group" data-toggle="buttons-radio">
   <button type=button data-toggle=button class="btn btn-primary" onClick="$('#blah').val(true);">Option1</button>
   <button type=button data-toggle=button class="btn btn-primary" onClick="$('#blah').val(false);">Option2</button>
</div>

It works perfectly, but there is slight problem. I can not set default Option. If I change class="btn btn-primary" to class="btn btn-primary active" on let say Option1 (to visually distinguish as default), the Toggling of the visual appearance of the buttons don't work any more i.e. once I click the opposite button they both stay visually active.

The problem is visual, internally the hidden field is set correctly, no problem with that.

How to make any of the buttons visually-default without breaking toggling visual behavior ?


原文:https://stackoverflow.com/questions/40031636
更新时间:2022-05-13 15:05

最满意答案

你只能做得稍微好一些。 如果您的C ++ / CLI类包含一些本机资源(通常是使用C ++ / CLI的唯一原因)并且您已正确实现了C ++ / CLI“析构函数”,即~Class1()方法:

using (var test1 = new Class1()) {
    test1.requirement();
}

这是有效的,因为每个C ++ / CLI类默认实现IDisposable并将~Class1()映射到Dispose的实现。


You could only do slightly better as you're already doing. If your C++/CLI class contains some native resources (usually the only reason to use C++/CLI) and you've properly implemented the C++/CLI "destructor" i.e. ~Class1() method:

using (var test1 = new Class1()) {
    test1.requirement();
}

This works because each C++/CLI class implements IDisposable by default and maps ~Class1() to an implementation of Dispose.

相关问答

更多
  • 对于托管类,您不需要__declspec(dllexport),因为它们会自动导出,除非您将它们声明为private / internal。 只需像这样改变班级签名: public ref class clr 另外,如果你想从C#中使用它,你应该在calculate方法的签名中使用托管数组: String^ calculate(array^ Robot_Points_Values, CameraSpacePoint* human_point_cloud, array
  • C#: class MyClass { public static string GetNameAndValue(out int value); } C ++ / CLI: int value; String^ x = MyClass::GetNameAndValue(value); C ++ / CLI包装器: CString GetNameAndValue(int* value) { String^ x = MyClass::GetNameAndValue(*value); ...
  • 这适用于本机C ++,因为它使用链接器。 如果没有人要求,会对缺少的成员实施感到满意。 但是这在托管代码中不起作用,它不使用链接器。 您的类定义将复制到程序集元数据中,并且绑定会在运行时动态发生。 这要求所有声明的成员都有一个表示,否则元数据将不完整,并且不支持,因为这会破坏反射。 即使是私人会员。 没有什么特别难以解决的, {}对于私有构造函数来说是一个非常好的实现。 This works in native C++ because it uses a linker. Which is happy wit ...
  • 事实证明这是一个操作系统问题。 在我注意到它在Windows 8.1 PC上工作正常后,我看了一下C ++ / CLI DLL的平台工具集设置。 要获得这些,请右键单击项目 - >属性 - >配置属性 - >常规。 当我应该定位“Visual Studio 2013 - Windows XP(v120_xp)”时,我的目标是“Visual Studio 2013(v120)”。 在我更改了该设置后,DLL开始在Windows XP计算机上运行。 It turns out this is an operati ...
  • 我想你必须定义: 公共参考课测试 在Test.hxx中 I think you must define : public ref class Test in Test.hxx
  • 我认为你刚刚完成了包装器中最难的部分。 现在,我将在包装器中创建一个事件,以将消息发送给它的任何订阅者。 让我给你看一个代码:H文件 // Define out custom delegate for event public delegate void StringEventHandler(String^ /*msg*/); ref class WrapperClass{ // ... rest of class declaration ... public: event StringEven ...
  • 我同意Taus: AccessViolationExceptions通常是由访问释放/未分配的内存或类似内容引起的。 管理员权限与此无关。 一个最小的例子将用于识别问题 编组程序通常会尝试创建该数据的托管(C#)表示,然后尝试释放/释放非托管数据(C ++)。 但是,您可能没有像编组程序期望的那样在C / C ++中分配内存,或者您可能没想到编组器会尝试为您释放内存。 如果默认的释放行为与您的用例不匹配,那么您可以通过在C#代码中使用IntPtr手动处理C ++对象的释放(如果有的话)。 例如,如果从非托管 ...
  • 使用C ++ / CLI,您可以随心所欲地获得所需的一切。 你可以这样做: #include #include extern "C" __declspec(dllexport) void __stdcall Example(char* name, char* greet) { // name will be passed to C# Test(...) function // and greet will contains ...
  • 好的,我终于完成了这个。 使用try&fail方法寻找解决方案花了好几个小时后,我尝试直接从C#代码中调用非托管DLL中的函数,然后调用包装器的构造函数,该函数在LoadLibrary调用中成功。 C#控制器中的代码现在看起来像这样: [DllImport("C:\\ManagerApp.dll", CharSet = CharSet.Unicode, EntryPoint = "?initFunc@ManagerAPI@@QAEHXZ")] private static exter ...
  • 你只能做得稍微好一些。 如果您的C ++ / CLI类包含一些本机资源(通常是使用C ++ / CLI的唯一原因)并且您已正确实现了C ++ / CLI“析构函数”,即~Class1()方法: using (var test1 = new Class1()) { test1.requirement(); } 这是有效的,因为每个C ++ / CLI类默认实现IDisposable并将~Class1()映射到Dispose的实现。 You could only do slightly better ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)