将第二个函数添加到按钮并禁用某些类

时间:2016-11-03 15:33:23

标签: jquery css wordpress

当浏览器窗口低于1000像素并添加(切换)新类时,我正在寻找摆脱某些类的方法。

public static void main(String[] args)
{
    Pattern p = Pattern.compile("^\\-?\\s?\\d+\\s?[\\+\\-*\\/\\^]\\s?\\-?\\s?\\d+\\r?\\n?$");
    System.out.println(p.matcher("123+").matches()); // outputs "true"
    System.out.println(p.matcher("123").matches()); // outputs "false"
    System.out.println(p.matcher("- 123123 *").matches()); // outputs "true"
    System.out.println(p.matcher("- 9843 * 23409").matches()); // outputs "true"
}

我是新手,我知道我的问题可能有点愚蠢,和我的代码一样。 我不知道你们是否还需要更多东西来帮助我,如果你这样做,只需输入内容即可。谢谢;)

1 个答案:

答案 0 :(得分:0)

您可以使用CSS媒体查询而不是JS。

简单示例:



var $btn  = $( 'button' );
var $lead = $( '.lead' );

$btn.on( 'click', function ( e ) {
  $lead.toggleClass( 'active' );
} );

.lead {
  font-size: 1.25rem;
}
.active {
  background-color: #fc0;
}

@media ( min-width: 650px ) {
  .lead {
    font-size: 1rem;
  }
  .active {
    background-color: #aa0;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="lead">
  Lateen sail yardarm swab dead men tell no tales warp heave down knave yawl aye man-of-war deadlights skysail me Cat o'nine tails jack ballast spirits stern Brethren of the Coast keel plunder aft interloper square-rigged pressgang. Crack Jennys tea cup reef sails deadlights long boat Pirate Round cackle fruit galleon keel heave to coxswain yo-ho-ho loot brig cog fathom jury mast hearties topgallant cable gabion league handsomely Jolly Roger spirits walk the plank. Pinnace boom measured fer yer chains loot Chain Shot jolly boat Buccaneer ho aft Yellow Jack rope's end matey sutler starboard spirits snow main sheet lookout Corsair ballast Pirate Round bilge cable Barbary Coast spike.
</p>
<p>
 Swing the lead lateen sail scuttle Blimey brig marooned warp belaying pin salmagundi Spanish Main yard crimp fire ship Sail ho splice the main brace gun starboard man-of-war code of conduct keel long clothes gibbet log grog blossom handsomely. Brig Yellow Jack landlubber or just lubber starboard crow's nest scuttle pinnace lugsail ho gangplank transom chase killick bounty mutiny maroon pirate Cat o'nine tails Jack Tar cutlass snow rigging matey splice the main brace Davy Jones' Locker. Wench overhaul quarterdeck crack Jennys tea cup Jack Ketch splice the main brace hulk grog driver starboard mizzen scurvy haul wind jack pink gally me strike colors walk the plank Barbary Coast transom hail-shot sloop Pirate Round long boat.
</p>
<button type="button" id="me">Click Me</button>
&#13;
&#13;
&#13;

第一部分由.active类表示。其目的是基于用户交互来说明媒体查询和状态。 .active有两种状态,由不同视口大小的背景颜色表示。通过单击按钮显示用户交互,也可以添加/删除.active

我还改变了第一段的字体大小,独立于任何页面事件,试图说明如何使用JS进行视觉(状态)更改。