如果选中单选按钮,则更改父 div (li) 背景 - javascript

2024-03-01

我在 li 元素内有单选按钮, 我想在选中单选按钮后更改 li (父 div)的背景颜色。我成功地通过 CSS 在 li 上设置了悬停,但 :checked 似乎不适用于父 div。 这是我的 html + css 代码:

.job-manager-term-checklist { 
    margin: 1em 0 0;
    padding: 0;
    list-style: none;
    overflow: hidden;
  }

.job-manager-term-checklist li {
    border: 1px solid #ccc;
    overflow: auto;
    padding: 5px;
    margin-left: 5px;
    border-radius: 5px;
    background-color: #ebf1f9;
    width: 20%;
  }

.job-manager-term-checklist li:hover { 
  background-color: #4e83ca;
  color: #fff;
  }
<div class="field required-field">
  <ul class="job-manager-term-checklist job-manager-term-checklist-job_category">
    <li id="job_listing_category-72" class="popular-category"><label class="selectit"><input value="72" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-72">1</label></li>
    <li id="job_listing_category-73"><label class="selectit"><input value="73" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-73">2</label></li>
    <li id="job_listing_category-75"><label class="selectit"><input value="75" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-75">3</label></li>
    <li id="job_listing_category-76"><label class="selectit"><input value="76" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-76">4</label></li>
    <li id="job_listing_category-80"><label class="selectit"><input value="80" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-80">5</label></li>
    <li id="job_listing_category-86"><label class="selectit"><input value="86" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-86">6</label></li>
    <li id="job_listing_category-98"><label class="selectit"><input value="98" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-98">7</label></li>
  </ul>
</div>

我将不胜感激有关此问题的任何帮助, 谢谢


虽然您已经接受了我建议的答案,但如果首选使用普通的非库 JavaScript,则如下所示:

// named function to handle the changes:
function toggleParentStyle(opts) {

  // the default settings:
  var settings = {

      // activeClass: String, the class-name by
      // which the 'active'/'on' state is denoted:
      'activeClass': 'active',

      // targetElementSelector: String,
      // the CSS selector to identify the elements
      // whose style is to be altered:
      'targetElementSelector': 'li',

      // uniquelyActive: Boolean, determines
      // whether only one element can have the
      // 'active' state/'activeClass' class-name:
      'uniquelyActive' : true
    },

    // caching the 'this' Node:
    trigger = this;

  // iterating over the (possibly) passed-in opts
  // Object that can be used to override the
  // default settings:
  for (var prop in opts) {

    // if the opts Object has prop as an
    // own-property (one not inherited from
    // the Object's prototype):
    if (opts.hasOwnProperty(prop)) {

      // we update the relevant property of
      // the settings Object to be equal to
      // that of the opts Object:
      settings[prop] = opts[prop];
    }
  }

  // caching the targetElementSelector and activeClass
  // with shorter names (for convenience):
  var selector = settings.targetElementSelector,
    c = settings.activeClass,

  // caching the closest ancestor of the element
  // triggering the function that matches the
  // selector:
    ancestor = trigger.closest(selector),

  // finding the currently-active element (if any),
  // moving from the found ancestor element:
    selectedSibling = ancestor

  // to its parentNode:
    .parentNode

  // finding the first/only element in that
  // parent element that matches the selector
  // and has the class-name:
    .querySelector(selector + '.' + c);

  // if settings.uniquelyActive is true, and
  // there is a selected-sibling:
  if (settings.uniquelyActive && selectedSibling) {

    // we remove the class-name:
    selectedSibling.classList.remove( c );
  }

  // here we access the ancestor element's classList,
  // and if the ancestor.classList.contains the class-name
  // (Boolean true) we use the 'remove' method, if it does not
  // contain the class-name (Boolean false) we use the 'add'
  // method, and pass the class-name as an argument:
  ancestor.classList[ancestor.classList.contains( c ) ? 'remove' : 'add'](c);

  // Note: for radio inputs this isn't necessary, as a radio
  // can't be changed by clicking it, but this might be a
  // necessary check were check-box inputs to be used instead.

}

// finding all the radio-inputs in the document:
var radios = document.querySelectorAll('input[type=radio]'),

// converting the HTMLCollection into an Array, using
// Array.prototype.slice and Function.prototype.call():
  radiosArray = Array.prototype.slice.call(radios, 0);

// iterating over the radiosArray using Array.prototype.forEach():
radiosArray.forEach(function(radio) {

  // binding the toggleParentStyle to handle the change
  // event of the radio inputs:
  radio.addEventListener('change', toggleParentStyle);
});
function toggleParentStyle(opts) {
  var settings = {
      'activeClass': 'active',
      'targetElementSelector': 'li',
      'uniquelyActive': true
    },
    trigger = this;

  for (var prop in opts) {
    if (opts.hasOwnProperty(prop)) {
      settings[prop] = opts[prop];
    }
  }

  var selector = settings.targetElementSelector,
    ancestor = trigger.closest(selector),
    c = settings.activeClass,
    selectedSibling = ancestor
    .parentNode
    .querySelector(selector + '.' + c);

  if (settings.uniquelyActive && selectedSibling) {
    selectedSibling.classList.remove(c);
  }

  ancestor.classList[ancestor.classList.contains(c) ? 'remove' : 'add'](c);

}

var radios = document.querySelectorAll('input[type=radio]'),
  radiosArray = Array.prototype.slice.call(radios, 0);

radiosArray.forEach(function(radio) {
  radio.addEventListener('change', toggleParentStyle);
});
.job-manager-term-checklist {
  margin: 1em 0 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
}
.job-manager-term-checklist li {
  border: 1px solid #ccc;
  overflow: auto;
  padding: 5px;
  margin-left: 5px;
  border-radius: 5px;
  background-color: #ebf1f9;
  width: 20%;
}
.job-manager-term-checklist li:hover {
  background-color: #4e83ca;
  color: #fff;
}
li.active {
  background-color: limegreen;
}
<div class="field required-field">
  <ul class="job-manager-term-checklist job-manager-term-checklist-job_category">
    <li id="job_listing_category-72" class="popular-category">
      <label class="selectit">
        <input value="72" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-72">1</label>
    </li>
    <li id="job_listing_category-73">
      <label class="selectit">
        <input value="73" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-73">2</label>
    </li>
    <li id="job_listing_category-75">
      <label class="selectit">
        <input value="75" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-75">3</label>
    </li>
    <li id="job_listing_category-76">
      <label class="selectit">
        <input value="76" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-76">4</label>
    </li>
    <li id="job_listing_category-80">
      <label class="selectit">
        <input value="80" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-80">5</label>
    </li>
    <li id="job_listing_category-86">
      <label class="selectit">
        <input value="86" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-86">6</label>
    </li>
    <li id="job_listing_category-98">
      <label class="selectit">
        <input value="98" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-98">7</label>
    </li>
  </ul>
</div>

JS 小提琴演示 http://jsfiddle.net/davidThomas/394qo1pg/

使用无线电显示上述内容<input>元素,但传递不同的设置:

radiosArray.forEach(function(radio) {
  radio.addEventListener('change', function () {

    // using Function.prototype.call()
    // to set the function's 'this' (the radio input),
    // and passing an Object as the second argument to
    // contain the Opts Object:
    toggleParentStyle.call(this, {

      // allowing multiple elements to be styled as active:
      'uniquelyActive' : false,

      // passing in a different class-name:
      'activeClass' : 'anAlternativeClassName'
    });
  });
});
function toggleParentStyle(opts) {
  var settings = {
      'activeClass': 'active',
      'targetElementSelector': 'li',
      'uniquelyActive': true
    },
    trigger = this;

  for (var prop in opts) {
    if (opts.hasOwnProperty(prop)) {
      settings[prop] = opts[prop];
    }
  }

  var selector = settings.targetElementSelector,
    ancestor = trigger.closest(selector),
    c = settings.activeClass,
    selectedSibling = ancestor
    .parentNode
    .querySelector(selector + '.' + c);

  if (settings.uniquelyActive && selectedSibling) {
    selectedSibling.classList.remove(c);
  }

  ancestor.classList[ancestor.classList.contains(c) ? 'remove' : 'add'](c);

}

var radios = document.querySelectorAll('input[type=radio]'),
  radiosArray = Array.prototype.slice.call(radios, 0);

radiosArray.forEach(function(radio) {
  radio.addEventListener('change', function () {
    toggleParentStyle.call(this, {
      'uniquelyActive' : false,
      'activeClass' : 'anAlternativeClassName'
    });
  });
});
.job-manager-term-checklist {
  margin: 1em 0 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
}
.job-manager-term-checklist li {
  border: 1px solid #ccc;
  overflow: auto;
  padding: 5px;
  margin-left: 5px;
  border-radius: 5px;
  background-color: #ebf1f9;
  width: 20%;
}
.job-manager-term-checklist li:hover {
  background-color: #4e83ca;
  color: #fff;
}
li.active {
  background-color: limegreen;
}
li.anAlternativeClassName {
  background-color: #f90;
}
<div class="field required-field">
  <ul class="job-manager-term-checklist job-manager-term-checklist-job_category">
    <li id="job_listing_category-72" class="popular-category">
      <label class="selectit">
        <input value="72" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-72">1</label>
    </li>
    <li id="job_listing_category-73">
      <label class="selectit">
        <input value="73" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-73">2</label>
    </li>
    <li id="job_listing_category-75">
      <label class="selectit">
        <input value="75" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-75">3</label>
    </li>
    <li id="job_listing_category-76">
      <label class="selectit">
        <input value="76" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-76">4</label>
    </li>
    <li id="job_listing_category-80">
      <label class="selectit">
        <input value="80" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-80">5</label>
    </li>
    <li id="job_listing_category-86">
      <label class="selectit">
        <input value="86" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-86">6</label>
    </li>
    <li id="job_listing_category-98">
      <label class="selectit">
        <input value="98" type="radio" name="tax_input[job_listing_category][]" id="in-job_listing_category-98">7</label>
    </li>
  </ul>
</div>

JS 小提琴演示 http://jsfiddle.net/davidThomas/394qo1pg/1/.

并展示它如何用于复选框:

// selecting inputs of type=checkbox:
var checkboxes = document.querySelectorAll('input[type=checkbox]'),

  // convert checkboxes HTMLCollection to an Array:
  checkboxArray = Array.prototype.slice.call(checkboxes, 0);

// exactly as above, but passing in different elements:
checkboxArray.forEach(function(check) {
  check.addEventListener('change', function () {
    toggleParentStyle.call(this, {
      // ensuring multiple checkbox ancestors can be
      // selected:
      'uniquelyActive' : false,
      'activeClass' : 'anAlternativeClassName'
    });
  });
});
function toggleParentStyle(opts) {
  var settings = {
      'activeClass': 'active',
      'targetElementSelector': 'li',
      'uniquelyActive': true
    },
    trigger = this;

  for (var prop in opts) {
    if (opts.hasOwnProperty(prop)) {
      settings[prop] = opts[prop];
    }
  }

  var selector = settings.targetElementSelector,
    ancestor = trigger.closest(selector),
    c = settings.activeClass,
    selectedSibling = ancestor
    .parentNode
    .querySelector(selector + '.' + c);

  if (settings.uniquelyActive && selectedSibling) {
    selectedSibling.classList.remove(c);
  }

  ancestor.classList[ancestor.classList.contains(c) ? 'remove' : 'add'](c);

}

var checkboxes = document.querySelectorAll('input[type=checkbox]'),
  checkboxArray = Array.prototype.slice.call(checkboxes, 0);

checkboxArray.forEach(function(check) {
  check.addEventListener('change', function() {
    toggleParentStyle.call(this, {
      'uniquelyActive': false,
      'activeClass': 'anAlternativeClassName'
    });
  });
});
.job-manager-term-checklist {
  margin: 1em 0 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
}
.job-manager-term-checklist li {
  border: 1px solid #ccc;
  overflow: auto;
  padding: 5px;
  margin-left: 5px;
  border-radius: 5px;
  background-color: #ebf1f9;
  width: 20%;
}
.job-manager-term-checklist li:hover {
  background-color: #4e83ca;
  color: #fff;
}
li.active {
  background-color: limegreen;
}
li.anAlternativeClassName {
  background-color: #f90;
}
<div class="field required-field">
  <ul class="job-manager-term-checklist job-manager-term-checklist-job_category">
    <li id="job_listing_category-72" class="popular-category">
      <label class="selectit">
        <input value="72" type="checkbox" name="tax_input[job_listing_category][]" id="in-job_listing_category-72">1</label>
    </li>
    <li id="job_listing_category-73">
      <label class="selectit">
        <input value="73" type="checkbox" name="tax_input[job_listing_category][]" id="in-job_listing_category-73">2</label>
    </li>
    <li id="job_listing_category-75">
      <label class="selectit">
        <input value="75" type="checkbox" name="tax_input[job_listing_category][]" id="in-job_listing_category-75">3</label>
    </li>
    <li id="job_listing_category-76">
      <label class="selectit">
        <input value="76" type="checkbox" name="tax_input[job_listing_category][]" id="in-job_listing_category-76">4</label>
    </li>
    <li id="job_listing_category-80">
      <label class="selectit">
        <input value="80" type="checkbox" name="tax_input[job_listing_category][]" id="in-job_listing_category-80">5</label>
    </li>
    <li id="job_listing_category-86">
      <label class="selectit">
        <input value="86" type="checkbox" name="tax_input[job_listing_category][]" id="in-job_listing_category-86">6</label>
    </li>
    <li id="job_listing_category-98">
      <label class="selectit">
        <input value="98" type="checkbox" name="tax_input[job_listing_category][]" id="in-job_listing_category-98">7</label>
    </li>
  </ul>
</div>

JS 小提琴演示 http://jsfiddle.net/davidThomas/394qo1pg/2/.

参考:

  • Array.prototype.forEach() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach.
  • Array.prototype.slice() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice.
  • Document.querySelector() https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector.
  • Document.querySelectorAll() https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll.
  • Element.classList https://developer.mozilla.org/en-US/docs/Web/API/Element/classList.
  • Element.closest() https://developer.mozilla.org/en-US/docs/Web/API/Element/closest.
  • EventTarget.addEventListener() https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener.
  • for...in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in.
  • Function.prototype.call() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call.
  • Node.parentNode https://developer.mozilla.org/en-US/docs/Web/API/Node/parentNode.
  • Object.hasOwnProperty() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如果选中单选按钮,则更改父 div (li) 背景 - javascript 的相关文章

  • Perl:HTTP::微小删除留下损坏的锚标记

    我编写了一个脚本 该脚本收集从数据库读取的缓冲区内的所有 URL 检查该页面是否仍然存在 并使用 HTTP Tiny 从缓冲区中删除 URL 如果该 URL 无法访问或返回无效 问题是 HTTP Tiny 删除左锚标记 例如此处无效的文本
  • 在 jQuery 可排序中对多个选定项目进行排序?

    我试图在 jQuery 可排序集中选择多个项目 然后将选定的项目一起移动 这是我的弱点开始尝试使其发挥作用 http jsfiddle net benstenson CgD8Y 这是代码 HTML div class container d
  • jQM / jquery-collagePlus 使用问题

    我正在使用 jQM 构建应用程序 并且尝试使用 jquery collagePlus http ed lea github io jquery collagePlus http ed lea github io jquery collage
  • 扩展位置绝对div超出溢出隐藏div

    我已经好几个月没有做过CSS了 所以我可能会错过一些简单的东西 但无论解决方案是什么 我都无法弄清楚 所以问题就在这里 这是我的代码的简化版本 div style height 100 width 200px div style margi
  • 如何更改自动完成中的结果过滤器?

    我不想进行字面匹配 而是想通过正则表达式选择结果 我可以覆盖自动完成的默认行为来完成此任务还是需要替代结构 有一个内置的方法可以做到这一点 只需提供一个函数source http jqueryui com demos autocomplet
  • ToggleClass 动画 jQuery?

    我的网站上有一个部分 当用户单击时我希望它展开 我正在使用 jQuerytoggleClass为了这 expandable function e e preventDefault this closest article toggleCla
  • 如何在CSS中制作一个带有边框的可调整大小的心形

    我想要制作一个心形 用户可以将其大小调整为任意宽度和高度 并且边框为 1 像素 我尝试了用纯 CSS 制作的心形 https stackoverflow com a 17386187 1404447 https stackoverflow
  • 为什么 Web Worker 性能在 30 秒后急剧下降?

    我正在尝试提高在网络工作人员中执行时脚本的性能 它旨在解析浏览器中的大型文本文件而不会崩溃 一切都运行得很好 但我注意到使用网络工作者时大文件的性能存在严重差异 于是我做了一个简单的实验 我在同一输入上运行脚本两次 第一次运行在页面的主线程
  • html css 下拉菜单

    这是我第一次在 Stack Overflow 上发帖 我不熟悉论坛发帖规定 所以请让我知道我做错了什么 我在论坛中研究过这个问题 但我所遇到的一切都没有给我明确的答案 我试图从 新闻 元素创建一个下拉菜单 但在运行代码时我从未得到任何可见的
  • Jquery 在 DIV 中进行多重加载

    这是我的代码 right load textes html nicolas right load textes html antoine 问题是内容divantoine覆盖了右边div nicolas加载的内容div div right l
  • Django - 提交具有同一字段多个输入的表单

    预警 我对 Django 以及一般的 Web 开发 非常陌生 我使用 Django 托管一个基于 Web 的 UI 该 UI 将从简短的调查中获取用户输入 通过我用 Python 开发的一些分析来提供输入 然后在 UI 中呈现这些分析的可视
  • 禁用特定 div 上的 Tab 键

    我有以下结构 div div Some content div div Some content div div 我想 禁用 div2 上的 tab 键 我的意思是按下 tab 键时 div2 的元素不会获得焦点 有没有简单的方法可以使用
  • 如何强制外部 div 扩展到内部 div 的高度?

    我有 ajax 到的数据 div class content 我希望外部 div 扩展到内部 div 的高度 我不知道该怎么做 HTML div class outer div class inner div class content S
  • 尝试在 React 应用程序中连接到 MySQL 数据库时,无法读取未定义的属性(读取“查询”)错误

    我正在尝试连接到 MySQL 数据库并在单击按钮后在 React 应用程序中运行查询 一些它如何给出错误 我当前的代码如下所示 import mysql from mysql function App async function sync
  • 元素和 svg 形状之间的白线

    大家好 我正在使用由 shapedivider 生成的 svg 整形器 您可以看到 有一条白线 我不知道为什么它在那里以及如何删除它 请你帮助我好吗 有形状分隔符的代码 custom shape divider bottom 1640714
  • RoR - Rails 中的大文件上传

    我有一个 Rails Web 应用程序 允许用户上传视频 视频存储在 NFS 安装的目录中 当前的设置适用于较小的文件 但我也需要支持大文件上传 最多 4GB 当我尝试上传 4GB 文件时 它最终会发生 但从用户体验的角度来看很糟糕 上传开
  • IE 中的每个 JavaScript 支持?

    我有这个代码
  • Node npm 包抛出使用严格:全局发布和安装后未找到命令

    我正在尝试发布 npm 包 当我全局安装该包并尝试运行 cli 命令时 我收到此错误 nvm versions node v0 12 2 bin myPack line 1 use strict command not found nvm
  • 将 RequireJS 与遗留代码结合使用

    我正在处理一个非常大的项目 该项目使用 包含带有脚本标记的 javascript 文件的旧版 JSP 页面 使用其他 javascript 模块而不使用 RequireJS 的骨干模型和视图 现在 我们希望开始将 RequireJS 与 j
  • Flowtype 属性“msg”缺失为 null 或未定义

    我发现 Flow 很难用 我明白那个Array find可以返回或未定义 因此 通过阅读以下内容 github Array find on Array 引发 https github com facebook flow issues 351

随机推荐

  • 无法从 powershell 运行 Elixir 应用程序

    当我打字时iex S mix在 PowerShell 中我收到此错误 Invoke Expression A positional parameter cannot be found that accepts argument mix At
  • 每行后动态重复标题行

    如何在 gridview 的每一行之后重复标题行 您可以将代码添加到网格的 rowdatabound event 中 protected void GridView RowDataBound object sender GridViewRo
  • Extjs XTemplate 两个同级数组循环?

    我想将 XTempate 与以下 json 数据一起使用 在另一个数组中循环一个数组 var data name xxx rowTitleArr 1 2 3 colTitleArr a b c var tpl name
  • 如何压缩包含超过 12GB 数据的文件夹

    我需要压缩一个包含大量文件的文件夹 当我尝试在命令行中进行压缩时 它显示压缩错误 输入文件读取失败 我搜索网络并发现 ZIP 文件格式 仅处理可以的文件长度 包含在 32 位整数中 如果是这样 那么它一定是我收到错误的原因 因为我的文件夹大
  • 如何使用asihttprequest接受自签名证书

    我正在尝试获取自签名证书来使用我的应用程序 我现在正在使用 ASIHTTPRequest 库 如下所示 IBAction sendHttpsRequest Set request address NSMutableString databa
  • 现在 CGI 脚本有哪些用途?

    我非常熟悉一般的 Web 编程语言 但我现在使用的工具之一是 CGI 我只能说 CGI 脚本相当慢 CGI 如今仍然普遍使用吗 如果不是的话 被什么取代了 是否存在 CGI 仍然存在并被积极使用的利基功能 CGI是协议 它是创建动态页面最基
  • 使用循环合并和创建表

    我尝试搜索如何使用循环合并和创建多个表 但找不到我正在寻找的内容 我有四个表 表 1 1 1 2 1 3 和表 2 表1 1 1 2和1 3共享相同的列但具有不同的行 表 2 与表 1 1 1 2 和 1 3 具有相同的第一列 具体来说 表
  • 防止线程在处理异常后分离时调用 std::terminate()

    我有自己的线程类 旨在帮助安全地管理异常 它看起来像这样 为了简单起见 跳过了其他构造函数和互斥体 class ExceptThread public std thread public template
  • 打开磁力链接而不失去焦点

    javascript 或其他 有没有办法在浏览器失去焦点的情况下处理磁力链接 这有点像在后台打开一个选项卡而不离开当前页面 我最近遇到了类似的问题 并且能够通过在页面上创建命名框架并将其用作目标来解决该问题window open windo
  • 正则表达式:一次性获取没有扩展名的文件名?

    我只想使用正则表达式获取文件名 所以我一直在尝试简单的事情 例如 当然 只有当文件名具有一个扩展名时才有效 但如果是的话adfadsfads blah txt我只是想adfadsfads blah 我怎样才能用正则表达式做到这一点 关于大卫
  • 检查 C 中的溢出

    让我们有 int a b c may be char or float anything actually c a b 让int类型用4个字节表示 假设 a b 需要比 4 个字节多 1 位 即 假设结果是 1 00 0 32 个零 二进制
  • Surface SDK 可以在 Visual Studio 2012 上运行吗?

    我需要使用 Surface SDK 创建一个 WPF 应用程序 我正在使用 Visual Studio 2012 并且根据this https stackoverflow com questions 11624895 how can i u
  • AndroidNotification.Builder与NotificationCompat.Builder[重复]

    这个问题在这里已经有答案了 我看到的几乎所有 Android 通知示例代码似乎都使用了NotificationCompat 我已经使用Notification Builder编写了自己的代码 我不清楚使用NotificationCompat
  • 我应该如何多次插入多条记录?

    我有一个名为Entry声明如下 class Entry string Id get set string Name get set 然后是一个接受多个这样的方法Entry使用 ADO NET 插入数据库的对象 static void Ins
  • 两次之间经过的小时数,与国家/地区和时区无关

    我们如何确定两次之间经过的小时数 例如 旧金山下午 3 30 迪拜下午 7 30 我不清楚的部分是 是否存在通过考虑时区和国家来计算减去的时间跨度的通用方法 我使用 C 作为主要语言 任何帮助将不胜感激 提前致谢 您询问的是 旧金山下午 3
  • 如何在Python中使用wrap_strategy来处理谷歌表格?

    我有一个 python 代码 它使用驱动器和工作表 api 来列出文件夹内的文件 我在这个文件夹中有多个谷歌工作表 其中一些在文本之间有空格 就像图片中给出的那样 我想使用 googlesheet api 将所有单元格的文本换行更改为溢出
  • iOS - 具有自动布局的比例间距

    我正在尝试使用界面生成器创建一个完美的比例视图 到目前为止 一切都很好 我正在以编程方式缩放字体 按钮等 唯一的问题是元素之间的约束 间距 保持不变 我想避免为间距限制创建出口 因为它看起来很混乱 我希望元素之间的间距在拉伸元素时保持成比例
  • 使用用户名通过 https 配置 WCF 以获得 WS-Security

    我正在尝试使用 WCF 客户端通过 https 调用基于 Java 启用 WS Security 的 Web 服务 但似乎无法获得正确的安全配置 使用 SvcTraceViewer 我在尝试过的任何安全配置中都没有看到预期的安全标头 我最近
  • Android Studio“运行应用程序”对话框不会出现在一个项目中,但会出现在另一个项目中

    我正在用 Android Studio 制作一个非常简单非常愚蠢的应用程序来了解如何保存关键首选项 但我遇到了一个奇怪的障碍 我会尽力提供尽可能多的信息 因为可能很难重现这个错误 但老实说 我正在运行的两个应用程序都是超级基础在那里没有编译
  • 如果选中单选按钮,则更改父 div (li) 背景 - javascript

    我在 li 元素内有单选按钮 我想在选中单选按钮后更改 li 父 div 的背景颜色 我成功地通过 CSS 在 li 上设置了悬停 但 checked 似乎不适用于父 div 这是我的 html css 代码 job manager ter